I am facing issue creating PDF file from HTML text stored in a variable. I have tried zendpdf but it directly prints tags also.

Here's my code:

$pdf = new \Zend_Pdf();
$page = $pdf->newPage(\Zend_Pdf_Page::SIZE_A4);
$pdf->pages[] = $page;
$page->setFont(\Zend_Pdf_Font::fontWithName(\Zend_Pdf_Font::FONT_HELVETICA), 20);
$page->drawText('<h1>hello</h1>', 100, 510);
$pdfData = $pdf->render();
header("Content-Disposition: inline; filename=result.pdf");
header("Content-type: application/x-pdf");
echo $pdfData;
  • thanks for response bt it have some errors – Adarsh Shukla Mar 15 '19 at 9:33
  • PHP Fatal error: Uncaught Error: Call to a member function get_cellmap() on null in /var/www/html/m21/vendor/dompdf/dompdf/src/FrameReflower/TableCell.php:37\nStack trace:\n#0 /var/www/html/m21/vendor/dompdf/dompdf/src/FrameDecorator – Adarsh Shukla Mar 15 '19 at 9:33
  • putting this '<h1>hello</h1>' into a variable, like this $text = '<h1>hello</h1>' and from there you can use the variable, $page->drawText($text, 100, 510); – fmsthird Mar 15 '19 at 10:07
  • @magefms it prints tags also – Adarsh Shukla Mar 15 '19 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.