[10 Solved Answers]-Convert HTML + CSS to PDF with PHP
we have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML.
ways of converting it to PDF.
DOMPDF: it had huge problems with tables. we figured out that our large nested tables and it helped (before it was just consuming up to 128M of memory then dying—that’s the limit of memory in php.ini) but it works completely in tables and not in images. The tables were just basic stuff with some border styles to add some lines at various points;
HTML2PDF and HTML2PS: It rendered some of the images (all the images are Google Chart URLs) and the table formatting was much better but it seemed to have some complexity and it keeps dying with unknown node_type() errors.
Htmldoc: It works fine on basic HTML but has almost no support for CSS whatsoever so we have to do everything in HTML so it’s useless to us.
we tried a Windows app called Html2Pdf Pilot and it works perfect but we need something which slightly runs on Linux and ideally runs on-demand via PHP on the Webserver.
use MPDF
a) extract in our folder
b) create file.php in our folder and insert such code:
$client = new Pdfcrowd("username", "apikey"); $pdf = $client->convertURI('http://bbc.co.uk/'); ?>
converts a web page and sends the generated PDF as an HTTP
php javascript
<?php require 'pdfcrowd.php'; try { // create an API client instance $client = new Pdfcrowd("username", "apikey"); // convert a web page and store the generated PDF into a $pdf variable $pdf = $client->convertURI('http://www.google.com/'); // set HTTP response headers header("Content-Type: application/pdf"); header("Cache-Control: max-age=0"); header("Accept-Ranges: none"); header("Content-Disposition: attachment; filename=\"google_com.pdf\""); // send the generated PDF echo $pdf; } catch(PdfcrowdException $why) { echo "Pdfcrowd Error: " . $why; } ?>
<?php $dompdf = new DOMPDF(); $dompdf->set_paper("A4"); // load the html content $dompdf->load_html($html); $dompdf->render(); $canvas = $dompdf->get_canvas(); $font = Font_Metrics::get_font("helvetica", "bold"); $canvas->page_text(16, 800, "Page: {PAGE_NUM} of {PAGE_COUNT}", $font, 8, array(0,0,0)); $dompdf->stream("sample.pdf",array("Attachment"=>0));
This article provides some of the basic informations on css , php html , javascript html , html php , php web design , php javascript , html css javascript , php in html , javascript online editor , js online , php website , html style , javascript online , css editor online , javascript in php , html & css , online css editor , css website , html in php , css style , html to php , code editor online , css code , html script , css javascript , javascript editor online , online html editor with css , online javascript editor , javascript examples with code web design , html css editor , how to create a website using html , html and css editor , ajax data , php web development , how to make a website using html , css and html.
Wikitechy Founder, Author, International Speaker, and Job Consultant. My role as the CEO of Wikitechy, I help businesses build their next generation digital platforms and help with their product innovation and growth strategy. I'm a frequent speaker at tech conferences and events.
interesting
good
Nice one