HTML To PDF High Resolution

Possible Duplicate:
Convert HTML + CSS to PDF with PHP?

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


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.


Try: "wkhtmltopdf" it just work great (and its -open source-). It uses webkit engine (used by safari, chrome browsers) and it is very easy to use :

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

Try it! for Linux and Windows as well. Easy to install. If you use ubuntu, type:

aptitude install wkhtmltopdf

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:

  • Using library provided, you can try html2pdf (php). In java / .net a library like pd4ml can be used (even it is not free).

  • 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 html2pdf.

    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 CSS parser I think)

    链接地址: http://www.djcxy.com/p/88536.html

    上一篇: 将HTML文件转换为PDF

    下一篇: HTML为PDF高分辨率