HTML to PDF High Resolution

Possible duplicate:
Convert HTML + CSS to PDF using PHP?

I want to convert a webpage to high resolution PDF suitable for printing. How can i do this?

0
source share
3 answers

If you want to do this in code, look at HTML2PDF or FPDF, these are php libraries designed to create PDF documents with code.

If you combine HTML2PDF with PHP output buffering functions, i.e.

<?php ob_start(); ?> // put all your html in here <?php $data = ob_get_contents(); require('html2pdf.php'); $pdf = new HTML2FPDF(); $pdf->AddPage(); $pdf->WriteHTML($data); $pdf->Output(); ?> 

Obviously this is a very crude example, but I used it before in php to create PDF files. He has some problems with styles, they seem to ignore most of them. But more control can be gained by using FPDF yourself and manually creating documents.

+1
source

if you want to convert a web page using a browser, you can use the software in windows such as cutepdf, dopdf, etc. but if you want to convert a web page to pdf using php code (on the fly), there are several ways to convert:

  • Using the provided library, you can try html2pdf (php). A java / .net library can be used, for example pd4ml (even if it is not free).

  • You can use an open converter. It can open several types of documents and convert them to pdf. Open office provides an API (I tried in java, not php). The stream is the same as you open the document and then convert to pdf, but you just do it in your encoding. Must have an open desktop server to listen to the converter through your code. See here http://oodaemon.sourceforge.net/

If you want a quick solution in PHP, perhaps you can use html2pdf.

The advantage with which you use an open office converter is the same as what you see in the browser (I have already tested its use of oodaemon). If you use a library, I'm not sure that 100% it will be the same if you open it in a browser, because the layout is CSS dependent. pd4ml generate layout in html and css pdf-base (does it have its own CSS parser, which I think)

+1
source

Try: wkhtmltopdf "it just works fine (and its -open source-). It uses the webkit engine (uses safari, Chrome browsers), and it is very easy to use:

 wkhtmltopdf stackoverflow.com/questions/1878512/ output.pdf 

Give it a try! for Linux and Windows. Easy to install. If you are using ubuntu, enter:

 aptitude install wkhtmltopdf 
+1
source

All Articles