After a discussion with Pawel Stroinski on our forum, the THtmlView component was used to make a tool converting any html document into pdf, i.e. "printing" a html document as a pdf.

I downloaded via SVN the latest THtmlView source code available from the successor of the well-known HTMLViewer components for Delphi (previously sold by, i.e. r36.

Then I compiled it under Delphi 7. Some errors in the code. I therefore fixed them. Then try to compile under Delphi 2010 - a lot of warnings, and some main feature not working as expected (like css support). Fixed most bugs, and made a lot of code refactoring - a lot of warning remains, and the component is not truly Unicode: THtmlView use internaly UTF-8 encoding. But it works better than the original version.

Then I used Pawel Stroinski's code using our SynPdf unit to produce a pdf file from any html content.

Some bitmaps where not printed: fixed some part of the SynPdf library (now in version 1.8.3 in our source code repository).

And since the code from THtmlView did rely on jpeg.pas and was handling PNG just with Delphi 2010, I added a compilation define (set by default) in order to use our SynGdiPlus library to read GIF, PNG and JPEG files. So the resulting executable is smaller in size (less than 890 KB), and work as expected. If you don't like all this, and need GIF animated in your PDF (??? it's a joken pdf doesn't allow this), you can turn the compilation define OFF, and use the previous code.

I've uploaded the source code in the HtmlView sub directory of our Source Code Repository.

You can download an executable file from

Just extract the htm2pdf.exe file in a directory, then launch it:

Click on the "Open" button to open a html file, then browse it on the screen, update the parameters below (like margins or paper size), and click on the "Save as" or "Save" buttons.
A pdf file will be created, containing the whole html content, together with the files.

As a demo, I included in the HtmlView/demo sub directory of our Source Code Repository some html, css and picture files. 

You can download the resulting pdf from

This htm2pdf tool can be used from the command line, without the GUI window above:

1. you'll observe that the last used parameters are saved in a htm2pdf.ini file in the same directory than the executable.

If you launch

htm2pdf /silent

all parameters from htm2pdf.ini will be used, no GUI will be displayed, and the conversion will be made.

2. you can force to specify a html source file name, and an optional destination pdf file:

htm2pdf sample.htm

will create a sample.pdf file in the same directory as sample.htm

htm2pdf sample.htm dest.pdf

will create a dest.pdf file

This tool is released under the Public Domain, free but with no warranty at all.

Discussion and comments are welcome on our forum: