In your projects you may need to convert HTML content to PDF for various reasons: transfer, storage, print.

The presentation below will try to guide you how to do it, using PHP, Java or ASP.

When available, we concentrate on open-source or free solutions as first choice.

If you want to contribute with another solution, please feel free to contact me.

HTML to PDF with PHP

This solution uses HTML2PDF project ( It simply gets a HTML text and generates a PDF file. This project is based upon FPDF script (, which is pure PHP, not using the PDFlib or other third party library. Download HTML2PDF, add it to your projects and you can start coding.

Code example

require("html2fpdf.php"); $htmlFile = ""; $buffer = file_get_contents($htmlFile); $pdf = new HTML2FPDF('P', 'mm', 'Letter'); $pdf->AddPage(); $pdf->WriteHTML($buffer); $pdf->Output('test.pdf', 'F');

HTML to PDF with Java

You can use be available on the same computer or in your network) for document conversion.

Besides HTML to PDF, there are also possible other conversions:
doc --> pdf, html, txt, rtf
xls --> pdf, html, csv
ppt --> pdf, swf

Code example

import officetools.OfficeFile; // this is my tools package ... FileInputStream fis = new FileInputStream(new File("test.html")); FileOutputStream fos = new FileOutputStream(new File("test.pdf")); // suppose runs on localhost, port 8100 OfficeFile f = new OfficeFile(fis,"localhost","8100", true); f.convert(fos,"pdf"); ...

How to get my Java tools package for

If you want to use this solution in your projects, please contact me:

HTML to PDF with ASP

You can use AspPDF (, an ActiveX server component for dynamically creating, reading and modifying PDF files.

Code example(VB)

Set Pdf = Server.CreateObject("Persits.Pdf") Set Doc = Pdf.CreateDocument Doc.ImportFromUrl "" Filename = Doc.Save( Server.MapPath("test.pdf"), False )