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>
Related
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>
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');
I am trying to working with DomPDF where I wanted to print some data.But the problem is inline CSS not working on that.Means it can't render the inline CSS though it works perfectly in HTML view How can I make it work. Any possible suggestion please ?
Here is my blade page to convert PDF
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<div class="main">
<h3 style="text-align:center"><u>X-Ray Invoice</u></h3>
<p><strong>Box Number:</strong> {{$customer->box_number}}</p><br>
<p style="float:right; margin-top: -38px;margin-right: 230px;"><strong>Custromer ID:</strong> {{$customer->uniqueId}}</p><br>
</div>
</body>
</html>
Here is the controller code :
$pdf = PDF::loadView('pdf.test', compact('customer'));
return $pdf->download('inovice.pdf');
And here is the output
I have a question for you, so I tried to export pdf document with php using dompdf,all goes well but when I send php variables to display it's add to the end and the beginning .%27
public function generateTitlePage($number_cadastral='')
{
$this->load->library('dompdf_gen');
$dompdf = new DOMPDF();
$html = <<<HTML
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="TitlePage.css" />
</head>
<body>
<div style="margin-top: 100px; text-align: right; padding-right:100px;">
Number:$number_cadastral
<div style="width: 150px;margin-left: 535px;size:1;"><hr style="margin:0px;"></div>
</div>
<div>
</body>
</html>
HTML;
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("welcome.pdf");
In this case variable $number_cadastral is preceded .%27, so the result will be: %27.787883434.%27.Why add this %27??Help me please
<?php
$number_cadastral = ($number_cadastral != "")?preg_replace('/[%]+/','', $number_cadastral):"";
public function generateTitlePage($number_cadastral){
$this->load->library('dompdf_gen');
$dompdf = new DOMPDF();
$html = '
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" media="screen" href="TitlePage.css" />
</head>
<body>
<div style="margin-top: 100px; text-align: right; padding-right:100px;">
Number:'.$number_cadastral.'
<div style="width: 150px;margin-left: 535px;size:1;"><hr style="margin:0px;"></div>
</div>
<div>
</body>
</html>
';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("welcome.pdf");
}
?>
Try this code.
I want to give a color to my string ,but dompdf doesn't allow me. this is my html code :
<style type="text/css">
.red{
color:#574595;
}
</style>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
I tried 3 possible way, but neither don't work. How can I manage that ?
this is my full code :
<?php
ini_set("gd.jpeg_ignore_warning", 1);
set_include_path(get_include_path() . PATH_SEPARATOR . "dompdf");
require_once('dompdf/dompdf_config.inc.php');
$category = $_GET['c'];
$dompdf = new DOMPDF();
$html =
'<html>
<head>
<style type="text/css">
.red{
color:#574595;
}
</style>
</head>
<body>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$output = $dompdf->output();
file_put_contents("pdf_generated/file.pdf", $output);
header("Location: http://acros.netlogiq.info/pdf_generated/file.pdf");
?>
and this is the result:
Check it out this is an example:
http://jsfiddle.net/C6bQf/
Code:
<style>
.red{
color: red;
}
</style>
<div style="color: red;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
Save your file as HTML.
Just tried your code here: http://www.digitaljunkies.ca/dompdf/examples.php
HTML:
<html>
<head>
<style type="text/css">
.red{
color:#574595;
}
</style>
</head>
<body>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
</body>
</html>
And its working, I got red color font. Check your configuration settings once.
EDIT:
DOMPDF PHP CODE:
<?php
require_once "../dompdf_config.inc.php";
ini_set("gd.jpeg_ignore_warning", 1);
$dompdf = new DOMPDF();
$html =
'<html>
<head>
<style type="text/css">
.red{
color:#574595;
}
</style>
</head>
<body>
<div style="color:#574595;">asdfsdfsd</div><br>
<font color="red">TRALALAL</font><br>
<div class="red">TRALALAL</div><br>
</body>
</html>';
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));
exit(0);
?>
I tried this and I am getting font color. Check your configuration. Configuration UI can be displayed here: localhost/dompdf/www/setup.php
(I hope you have the same folder structure available)