views:

205

answers:

2

I want to convert a web page to a high-resolution PDF suitable for printing. How can I do this?

+1  A: 

If you want to do it in code, have a look at HTML2PDF or FPDF, they are php libraries designed to create PDF documents with code.

If you combine HTML2PDF with PHP's output buffering functions ie

<?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 that is a very rough example but I have used that before within php to generate pdfs. It does have some issues with stylesheets, it seems to ignore most of them. But more control can be gained by using FPDF by itself and manually building the documents.

Tim
+1  A: 

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

  1. using library provided, you can try html 2 pdf (php). in java / .net, a library like pd4ml can be used (even it is not free).

  2. You can use open office converter. it can open multiple doc type, and convert into pdf. Open office provide API (I have tried in java, not php). The flow is same like you open the document, then convert into pdf, but you just do it in your coding. Must have open office server daemon to listen the converter via your code. See here http://oodaemon.sourceforge.net/

If you want quick solution in PHP, maybe you can use html 2 pdf.

The advantage you use open office converter is the output will be same as you see in browser (I already test it use oodaemon). If using library I am not sure 100% it will be same if you open in browser, because the layout is depend on CSS. pd4ml generate layout in pdf base on html and css (has it owns logic css parser I think)

Jef
hi jeft, what i want to convert is using software, currently i tried nitro pdf trial version but when i convert html, it doesn't include any images from that html. And cutepdf, i am trying to convert html, but i don't know how to ? Any good software to test ? I want the high resolution pdf file to print. That's why.
spotlightsnap
Sure, you can test doPDF (free), or pdfFactoryPro (not free)pdf Factory Pro can convert any document (as long as you can print it) to pdf. open html / word / anything, then click print, and choose pdf factory pro.if you want to good resolution for image, choose the pdf factory pro properties - graphic tab. Uncheck downsample images to and uncheck use jpg compression.It works for me.
Jef