mPDF footer is not showing - php

I am using a basic html structure for my PDF template together with <htmlpagefooter> according to the mPDF docs.
A sample implementation can be found here
<html>
<head>
<style>
.mydiv {
color: red;
}
</style>
</head>
<htmlpagefooter name="myfooter">
Page {PAGENO} of {nb}
</htmlpagefooter>
<sethtmlpagefooter name="myfooter" value="on" />
<body>
<div class="mydiv">
This is my PDF file
</div>
</body>
</html>
When I generate my PDF it will refuse to show the footer on any page. When I put PHP code inside it will throw an appropriate error proving that it is parsed into the mPDF.

Because you are using a <body> tag inside an <html> tag, you have to make sure your footer is included in code that will be rendered on a page.
When you include the footer outside of the body, it will not be shown in the PDF.
When you include the footer inside the body, it will render as expected.
So a succesfull implementation of a footer in mPDF would look like this;
<html>
<head>
<style>
.mydiv {
color: red;
}
</style>
</head>
<body>
<htmlpagefooter name="myfooter">
Page {PAGENO} of {nb}
</htmlpagefooter>
<sethtmlpagefooter name="myfooter" value="on" />
<div class="mydiv">
This is my PDF file
</div>
</body>
</html>

Related

Pass Html button through a WordPress Plugin with add_shortcode

I'm making wordpress plugin through wp-content/plugins folder and I want to pass Dropbox button into a specific page but I get undefined add_shortcode
this's the html code I want to pass in the plugin currently indeed
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="style.css">
<!-- Dropbox library for importing the Dropbox button the webpage -->
<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs"
data-app-key="XXXX></script>
<body>
<div class="dropbox_btn" style=" margin: auto !important; width: 50% !important; ">
<!-- dropboxContainer is the id of Dropbox button which will be added in script.js file -->
<div id="dropboxContainer"></div>
</div>
</body>
</html>
<?php
define("ABSPATH", "C:/xampp/htdocs/wordpress/");
require_once(ABSPATH . 'wp-includes/shortcodes.php');
require_once(ABSPATH . 'wp-includes/functions.php');
function dropbox()
{
$text = "Dropbox APi Plugin";
return $text;
}
add_shortcode('example', 'dropbox');

How to get multiple pages with Dompdf

I'm using dompdf in Magento 2 to download the multiple PDFs for an invoice but getting only one page. Can someone please help me?
$domPdf = new Dompdf();
$domPdf->loadHtml($html);
$domPdf->setPaper('A4', 'portrait');
$domPdf->render();
This is the code to convert to PDF.
Thanks in advance
Unfortunately it requires additional work to realize multi page. You have to custom style your HTML string used for the loadHtml function to support multi page. For example:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="page">
this is page 1
</div>
<div class="page">
this is page 2
</div>
<div class="page">
this is page 3
</div>
</body>
<style>
.page {
page-break-after: always;
}
.page:last-child {
page-break-after: unset;
}
</style>
</html>

Sticky footer when including footer.php

I was wondering how I could make my footer stick to the bottom of the page, no matter how long the page is. I'd include my footer.php file by using include('footer.php') at the bottom of every page. I have already searched for a good answer but nothing I found works because every tutorial assumes you make your footer on every single page instead of including it. Does anyone know what CSS i'd have to use to be able to do this?
Footer HTML:
<html>
<body>
<footer>This is my footer</footer>
</body>
</html>
Index.php example:
<html>
<head>
<?php
include('nav.php');
?>
</head>
<body>
<p>Blah blah blah</p>
<?php
include('footer.php')
?>
</body>
</html>
Thank you
I think your footer.php file should contain only footer element and its content:
<footer>...</footer>
then add to your css:
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px; // or any suitable height
display: block;
}
html {
position: relative;
min-height: 100%;
}
I'm not sure, but you may also need to include white space at the bottom of your page content to avoid some of it being blocked by your footer.
I don't think you can close and open the body and the html twice, when you do it like this that's how the html page look like:
<html>
<head>
<?php
include('nav.php');
?>
</head>
<body>
<p>Blah blah blah</p>
<html>
<body>
<footer>This is my footer</footer>
</body>
</html>
</body>
</html>
so you should make the footer like this:
<footer>This is my footer</footer>
</body>
</html>
and your html page like this:
<html>
<head>
<?php
include('nav.php');
?>
</head>
<body>
<p>Blah blah blah</p>
<?php
include('footer.php')
?>
And if I understood you correctly your css should contain position:fixed as you can read here: https://www.w3schools.com/cssref/pr_class_position.asp

PHP CSS :: inline work but not internal and external stylesheet

I have created PHP files which accept data from $_GET method.
After that I use all the data I get to create HTML pages. Nothing is wrong with the data but in CSS I cannot style HTML elements. Except when it comes to inline styling, that works but it is not good to maintain.
I try to use like this but it doesn't work , Please Help
THANK IN ADVANCE
Example.php
<?php
$dataCover = $_GET['dataCover'];
$dataTitle = $_GET['dataTitle'];
$dataTag = $_GET['dataTag'];
$dataDir = $_GET['dataDir'];
$dataYear = $_GET['dataYear'];
$dataCreated = $_GET['dataCreated'];
$dataModified = $_GET['dataModified'];
$userAUID = $_GET['userAUID'];
$galleryID = $_GET['galleryID'];
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css" media="all">
#container img{
height: 230px;
width: 200px;
}
#container .center{
display: block;
margin: 0 auto;
}
</style>
<script src="../lib/jquery-1.10.2.min.js"></script>
<script src="../lib/jquery.mobile-1.3.1.min.js"></script>
<script src="../lib/se.js"></script>
</head>
<body>
<div data-role ="page" id ="page1">
<div data-role ="header">
<h1> header </h1>
</div>
<div data-role="content">
<div id="container">
<img class="center" src="<?echo $dataCover?>" alt=""/>
<p id="title"><?echo $dataTitle;?></p>
<p id="tag"><?echo $dataTag;?></p>
<p id="created">Created : <?echo $dataCreated?></p>
<p id="modified">modified : <?echo $dataModified?></p>
View Ebook-Gallery
Bookmark
</div>
</div>
</div>
</body>
</html>
When you move your css from inline to style sheet file, you have to refresh your page with Ctrl+F5. Maybe it's coming from the cache.
Also you can assign your css to the image by jquery.
I dont see any reference to any external stylesheet, so it seems like you have forgotten to do this.
Put this line
<link rel="stylesheet" type="text/css" href="/css/style.css" />
Somewhere in the head. Maybe before the script tags.
Make sure you adjust the path to your stylesheet.
Yes When you want to apply external css you have to give the path after the <title> tags within the <head> tags .just follow the html code
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
<!--Here css is the folder name where you have keep the style.css file -->
<script src="../lib/jquery-1.10.2.min.js"></script>
<script src="../lib/jquery.mobile-1.3.1.min.js"></script>
<script src="../lib/se.js"></script>
</head>

min-height CSS property doesn't work while buffering output with PHP ob_start()

I'm actually working on a PHP project using MVC structure, including DOCTYPE & HEAD tag via a single file during an output buffering using ob°start().
The problem comes when i wanna declare a min-height property for may page container, in order to stick the footer at the bottem of the page. ob_start() -- ob_get_clean() use seems to forbid browsers to access these properties in time so they can't evaluate height value.
This is my index.php file:
<?php
include_once('global/init.php');
ob_start();
if(isset($_GET['module'])){
$module = dirname(__FILE__).'/modules/'.htmlspecialchars($_GET['module']).'/';
$action = (isset($_GET['action'])) ? htmlspecialchars($_GET['action']).'.php' : 'index.php';
if(!file_exists($module.$action)){
include('global/home.php');
}else{
include($module.$action);
}
}else{
include('global/home.php');
}
$content = ob_get_clean();
include_once('global/header.php');
echo $content;
include_once('global/footer.php');
the header.php file contains the doctype, and the first basics of html:
<html>
<head>
<meta charset='UTF-8' />
<title><?php echo "LiveSession".' '.DOMAIN_INFOS;?></title>
<meta name='description' content='<?php echo $_SESSION['currentDesc'];?>' />
<meta name='keywords' content='<?php echo $_SESSION['currentKWds'];?>' />
<link rel='stylesheet' media='screen and (max-width:480px)' href='css/smartphones.css' />
<!-- TABLETS -->
<script type='text/javascript' src='scripts/jquery.1.7.js'></script>
<script type='text/javascript' src='scripts/poll_edit.js'></script>
<script type='text/javascript' src='scripts/smartphones.js'></script>
</head>
<body>
<div id='page'>
<div id='header'>
<h1><a href='index.php'>InteractivePollSession</a></h1>
<?php
if(is_connected_user()){
echo "<span id='disconnector'><a href='index.php?module=members&action=dscnx' title='disconnect'>Disconnect</a></span>";
}
?>
</div>
<div id='contentWrap'>
the footer:
</div>
<div id='footer'>
<span id='central-footer'>© <a href='http://www.jsteitgen.com'>JSTeitgen</a></span>
</div>
</div>
</body>
And a basic css exemple:
body{height:100%;}
#page{min-height:100%; position:relative;}
#footer{position:absolute; bottom:0; width:100%;}
Does any one know how to fix this using ob_start() ?
Of course, every other CSS rules work fine except this ...
Thank's
JS
The ob_start() is not the problem. The problem is only a html/css problem. You can only use a height in percentage if the parent of the element has a fixed height.
In your case, #page parent is body and the body's height is 100%, so you can't use a height in percentage for #page. But you can try this for example :
body{height: 1000px;}
#page{min-height:100%; position:relative;}
#footer{position:absolute; bottom:0; width:100%;}
I think the problem is with the css; you are setting the body element's height to 100% of its parent, the html element, which does not necessarily have a height of 100%.
You should be able to solve your problem using:
html, body {
height: 100%;
}

Categories