While the default conversion settings produce great quality PDF files you may want to fine tune the conversion to get an even better result. This post provides tips on improving the quality of images and text in PDFs created with the Pdfcrowd HTML to PDF API.
The HTML content is scaled up by 1/3 by default when printed to PDF
which may cause some images to appear jagged. You can use the
setPdfScalingFactor API method to change the scaling and to print
the image in the original resolution:
Note: All API clients use 1.0 as the default value since the version 2.0.
This method is available in the latest version of all API client libraries. Also make sure that you use the PNG or GIF image formats for line drawings or other textual or iconic graphics. JPEG can cause noticeable artifacts when used for such type of images.
Note that if an HTML page is designed for a specific width which is greater than the PDF page width then the HTML content is automatically scaled down to fit the page width regardless of the scaling factor value.
Provide High Resolution Images
Even if you applied the previous tip there is still room for improvement. When a user opens your PDF in a viewer and zooms in, the images will be rendered in a higher resolution than they were designed for which will make them appear jagged or blurred.
Let's assume there is a 160×32 logo in your HTML document and you want to print it to PDF without quality degradation even when the PDF is zoomed in. The trick is to create a high resolution version of the logo, for instance 320×64, and then specify 160×32 dimensions in your HTML code:
<img src="logo320x64.png" width="160" height="32" />
Here is a demonstration - open this PDF file, try to zoom in to e.g. 400%, and see how the individual versions of the image are rendered.
If your HTML document contains text typed with a small size font then
some consecutive glyphs may seem a bit too close or too distant when
printed to PDF. The
setHtmlZoom API method can help here. Despite
its name, it does not change the font size but the precision used for
positioning the glyphs. The default value is
100%, values around
500% should improve the glyph spacing:
Note: All API clients use 200 as the default value since the version 2.0.
Let's look at the difference:
- HTML Zoom 100%
- HTML Zoom 500%