#1 2010-07-15 17:39:17

From: France
Registered: 2010-06-21
Posts: 14,355

htm2pdf free tool release

After a discussion with Pawel Stroinski on this 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 PBear.com), 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 http://synopse.info/files/pdf/htm2pdf.zip

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, the 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 http://synopse.info/files/pdf/sample.pdf

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.

Thanks Pawel for your idea, debugging and gui code!

Some margin problems fixed, thanks to another Pawel's report.

Both source code repository and executable file have been updated.


#2 2020-01-26 19:27:44

Registered: 2016-03-16
Posts: 163

Re: htm2pdf free tool release


I am searching for a way to print html files I have in certain order and without any user dialog intervention.

I thought easiest might be to convert them in to pdf and search ways of printing pdf without any user intervention. I am interested in free solutions.

I have found this htm2pdf tool. Tried it and I have below problems:
1- picture embedded in html is not visible.
2- text seems not UTF-8.
3- This maybe UTF-8 again, but even empty table cells are filled with some characters

Html source can be found in here: https://controlc.com/233e0de2
Generated PDF view can be found in here: https://files.fm/u/7ea5fdzn

I wonder if there is any way to fix these problems.

Thanks & regards,


Board footer

Powered by FluxBB