Is possible convert directly HTML into a pdf file using Zend_Pdf?, if so, How can I do that?
Is possible convert HTML into pdf using Zend_Pdf?
Asked Answered
Nope, I don't think this is what it was built for. framework.zend.com/manual/en/zend.pdf.introduction.html –
Phenylalanine
Although this might be Frankenstein-ish (and not really an answer to your question) I've used PHP to generate content, send the output buffer to a file, and used wkhtmltopdf to generate PDFs. –
Adigun
Zend_PDF
isn't able to generate PDF based on HTML. But you can render view and use other library for convert it to PDF. I've done such thing with TCPDF. Little code snippet below:
//SomeController.php
$this->_helper->layout->disableLayout();
//set content for view here
// create new PDF document
require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
//whole TCPDF's settings goes here
$htmlcontent = $this->view->render('recipe/topdf.phtml');
// output the HTML content
$pdf->writeHTML($htmlcontent, true, 0, true, 0);
$pdf->lastPage();
$pdf->Output("pdf-name.pdf", 'D');
Is there a chance you could go into more detail of an example of what somecontroller.php would be, and what goes in 'set content for view here'? Thanks! –
Ludlow
@Ludlow It's the exact same way in which you create normal controllers in ZF:
SomeController extends Zend_Controller_Action
. Same with view: $this->view->foo = 'bar'
. Whole trick is to render page as normal ZF page, but instead outputing it into screen, you catch this into variable $htmlcontent
and pass to TCPDF writeHTML()
method. –
Handiwork Thanks! I ended up working around it a different way, bu this help. –
Ludlow
like the approach but didn't work for me since i need to pass variable in the view via <code>$this->view->entities= $entities</code> All i got it the first th column... Any Hint? –
Stipel
sorry it was about unclosed tags –
Stipel
tcpdf is a little limited when it comes to html, wkhtmltopdf uses webkit
The question is regarding zend_pdf for which tcppdf, dompdf and mpdf are more sutiable. –
Julesjuley
Check out MPDF . The ultimate one. Create your html with inline css, store it in one php variable and echo to pdf file. you are done!!!
i've used dompdf https://github.com/dompdf/dompdf its pretty easy and straight forward. it even reads/formats css.
I tried to use dompdf for generating pdf from html, but it has a really annoying (known) issue: it puts a few empty pages between two table rows (at least in 0.6.0 beta 3) –
Cloistered
© 2022 - 2024 — McMap. All rights reserved.