I am created PDF using DOMPdf Every thing showing properly but image is not
showing.
<?php
$data1.='<p>Peace,</p><image src="http://localhost/manresaorg/im_Steve-Raymond-1.jpg"></p>Steve Raymond
<br>Associate Director';
$data1.='</main></div>';
?>
<?php
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($data1);
// (Optional) Setup the paper size and orientation
//$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
//$dompdf->stream("manresaorg.pdf");
$dompdf->stream("manresaorg.pdf", array("Attachment" => false));
exit(0);
?>
I tried absolute path like:->
<image src="E:\xampp\htdocs\manresaorg\im_Steve-Raymond-1.jpg">
But it is not showing image on PDF.I am using Xampp Server on window.
Related
A client of mine had a problem merging two pdf documents. When I looked into it, and ran the PDF file rendered by DOMPDF in a PDF validator, it outputs:
1.1: Header Syntax error, Second line must begin with '%' followed by at least 4 bytes greater than 127
Looking at a valid pdf, this is line 2: %ÓôÌá
The error does not originate from the html, as it occurs even with the default Hello World! example by DOMPDF:
require_once 'dompdf/autoload.inc.php';
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
Edit: Question is whether there is a way to make Dompdf create the missing line 2?
Should be said that the file can be opened and viewed but error arises when merging with another pdf file.
I am currently generating some pdfs with the dompdf library but every time a pdf is being generated my temp folder is being filled with this file and the images associated with it. I am trying to unlink or delete the pdf and any temp files generated with it but the following code is not giving the desired result. Does anyone know what else I can do in this situation?
I am using PHP and have installed the library with composer.
pdf code:
// reference the Dompdf namespace
use Dompdf\Dompdf;
// instantiate and use the dompdf class
$dompdf = new Dompdf();
//$dompdf->loadHtml('hello world');
$dompdf->set_option('isHtml5ParserEnabled', true);
$dompdf->set_option('isRemoteEnabled', true);
$dompdf -> loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
unlink($dompdf);
I have installed tangerine in my dompdf. Now what is happening is when i try on my windows machine it works fine. But in ubuntu when i put the same code in xampp the generated pdf is massed up. I used the tangerine font with only my h3 tags but in the generated pdf the font style is placed in whole body. Here is my dompdf settings
<?php
// Include autoloader
require_once 'dompdf/autoload.inc.php';
// Reference the Dompdf namespace
use Dompdf\Dompdf;
// Instantiate and use the dompdf class
$dompdf = new Dompdf(array('isPhpEnabled' => true));
// Load content from html file
ob_start();
include_once 'pdfcontent.php';
$output = ob_get_clean();
$dompdf->loadHtml($output);
//$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('b4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF (1 = download and 0 = preview)
$dompdf->stream("funeral",array("Attachment"=>0));
?>
Well the the problem was basically with the cached dompdf file. I have deleted the dompdf folder and uploaded again. Now it works fine.
I want to use dompdf in my php website and I try to include the library without Composer and I can not get it to work.
The code I try to test is:
<?php
include "../../plugins/dompdf/Autoloader.php";
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
?>
But i get the error:
Fatal error: Class 'Dompdf' not found ...
Can anyone explain me how to include the library without install composer in the server?
Thank You.
With the right include is working like a charm, as said Samrap i was including the wrong file.
Now the code is:
<?php
//Configure the directory where you have the dompdf
require_once "../../plugins/dompdf/autoload.inc.php";
use Dompdf\Dompdf;
//$dompdf = new dompdf();
//$dompdf = new DOMPDF();
$dompdf = new Dompdf();
$dompdf->loadHtml('hello world');
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
?>
Thank you Samrap for your help.
You're requiring the wrong autoload file. The docs clearly state to include this file for autoloading:
require_once 'dompdf/autoload.inc.php';
If you look at that file, you'll see it does require Autoloader.php but performs a few other bootstrapping tasks as well.
I want to use dompdf for generation pdf document.
i got pdf response with follwing code by using DOMPDFModule.But my question is how can i pass variable to the phtml file in order to get print on pdf file my code is as follows
use DOMPDFModule\View\Model\PdfModel;
...
..
public function printAction()
{
$campaignsList=$this->getcampaignTable()->getCampaignList();
$model = new PdfModel();
$model->setOption('paperSize', 'a4');
$model->setOption('paperOrientation', 'landscape');
return $model;
}
How can i print that $campaignList array in print.phtml file
Thanks in advance
I'm not 100% sure what you're asking, you can create the PDF entirely within your action without involving the view(presume this is what you meant when reference your phtml file).
Some example code on PDF generation with DOMpdf :
<?php
// Create a new DOMPDF object
$dompdf = new \DOMPDF();
// Set the paper size to A4
$dompdf->set_paper('A4');
// Load the HTML
$dompdf->load_html($html);
// Render the PDF
$dompdf->render();
// Set the PDF Author
$dompdf->add_info('Author', 'I am the Author');
// Set the PDF Title
$dompdf->add_info('Title', 'My PDF Title');
/**
* 'Attachment' => 1 or 0 - if 1, force the browser to open a
* download dialog, on (1) by default
*/
$dompdf->stream($name,array('Attachment'=>1));
?>
And the documented usage - DOMPDF LINK