A: The ExpertPDF HTML to PDF converter allows a very fine control of the PDF rendering
process. The default settings of the converter should be acceptable for majority
of the situations but sometimes more control and customizations are necessary. If
want to learn more about the HTML to PDF rendering please check this article.
The converter internally uses a virtual display where to render the HTML page very
similar to what the web browser does on the screen. This virtual display is different
from display of your computer and it has a fixed resolution on your computer (which
normally is 96 dpi) independent of the resolution of your computer screen. The web
page elements dimensions are usually measured in pixels and this is the reason why
the virtual display of the converter is also specified in pixels. These are the
only dimensions used by the converter which are expressed in pixels. All the other
dimensions are specified in points (1 point is 1/72 inches). However, because of
the fixed resolution of the virtual display, the pixels dimensions of your web page
can be easily converted to dimensions expressed in points . The converter API offers
the UnitsConverter class which can be used to convert dimensions from pixels to
points and from points to pixels.
You can specify the virtual display width and height in pixels using the PdfConverter.PageWidth
and PdfConverter.PageHeight properties or you can specify the same values as parameters
when you construct the PdfConverter object.
By default the PageWidth is set to 1024 pixels which should be sufficient to display
the majority of the web pages. If the web page you are converting cannot be completely
displayed in this width then you can increase this value or you can set the PageWidth
to 0 to allow the converter to automatically determine your web page width from
the HTML elements width. The PageHeight property is 0 by default which means the
virtual display will be automatically resized to display the whole HTML page. There
are situations when the converter cannot automatically determine the web page height
for example when the web page is a frame set. In this case you can manually set
the PageHeight to certain value in pixels such that the page is displayed in the
way you expect.
After the HTML content is displayed in the virtual display the virtual display content
will be transfered into PDF as you would take a picture of the virtual display and
put that picture into a PDF document. The PDF documents pages have a fixed size
in points. For example, the A4 page is 595 points in width and 842 points in height.
If the virtual display width is more than 595 points then the rendered HTML content
would be shrinked to fit the PDF page width and display the whole HTML content in
the PDF document. If the virtual display width is less than 595 points then
the rendered HTML content will not be resized and will be rendered in the top left
corner of the PDF page at real size.
The dimension of the A4 portrait page in virtual device pixels is 793x1122 pixels.
This means that at a default virtual display width of 1024 pixels the HTML content
will be shrunk to fit the PDF page. This is the reason why you see smaller fonts
and images in PDF.
In the version version 3.5.2 of the converter a new property FitWidth was added
to the PdfConverter.PdfDocumentOptions. The default value is true which makes the
HTML content to be resized if necessary to fit the PDF page width. When false, the
HTML content will not be resized and it will be rendered at the real size in PDF
(the size it has in the virtual display at the usual resolution of 96 dpi).
When the FitWidth property is false the HTML content could be wider than the PDF
page width and the therefore the HTML content will be cut off to the right in PDF.
In this case, in order to get the whole content in PDF you have to set a wider page
for the PDF document. You can first try to set landscape orientation for the PDF
page by setting PdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape.
If this not enough you can choose a wider standard page like A3 or A2. You can even
set a custom size for the PDF page. Starting with version 3.2 of the converter you
can set the PdfConvert.PdfDocumentOptions.PdfPageSize=PdfPageSize.Custom and in
this case the custom size of the PDF page will be taken from PdfConverter.PdfDocumentOptions.CustomPdfPageSize
property.
In version 4.0 of the HTML to PDF Converter product we added a new property PdfConverter.PdfDocumentOptions.AutoSizePdfPage
which is has effect only when the FitWidth property is false. When FitWidth is false
and AutoSizePdfPage is true, the PDF page width will automatically be resized to
a custom value such that all the HTML content is displayed in PDF at real size.
If you don't want to resize the PDF page but you want to keep it A4 portrait for
example, then you have to decrease the virtual display width. If your page can be
correctly and entirely displayed in 793 pixels (which is the width of the A4 portrait
page in pixels) you can set this value for PdfConverter.PageWidth property and you
should get the whole HTML rendered at real size in PDF.
The HTML content centering in PDF problem can be observed when the HTML content
can be normally displayed at a width less than 1024 pixels. In this case there will
normally be an empty space in the right side of the virtual display. When the virtual
display content is transfered to PDF the content will appear as not centered in
PDF. You can also solve this if you set the PdfConverter.PageWidth to a value of
793 pixels or less.