|
The Winnovative HTML to PDF Converter and the Winnovative PDF Creator products allow
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 is necessary.
PDF Document Page Orientation
You can set the PDF document page orientation to Portrait or Landscape. By default
the document page is A4 size Portrait orientation. To change the page orientation
to Landscape you have to set the PdfConverter.PdfDocumentOptions.PdfPageOrientation
property in HTML to PDF Converter or you can set the PDF page orientation when you
create a PDF page with PDF Creator. All the pages auto generated by the PDF
Creator during conversion will have the same orientation with the page where the
HtmlToPdfElement was placed.
With HTML to PDF Converter for .NET library you can set the landscape orientation
with:
PdfConverter.PdfDocumentOptions.PdfPageOrientation = PDFPageOrientation.Landscape
and with PDF Creator for .NET library you can create a new landscape page with :
Document.Pages.AddNewPage(PageSize.A4,
new Margins(10,10,0, 0), PageOrientation.landscape)
PDF Document Page Size
You can set the PDF page size to a standard size like A4, A3, etc or you can set
the PDF page size to a custom value. The custom page size width and height are specified
in points (1 point is 1/72 inches).
With the HTML to PDF Converter for .NET library you can set the PDF page size to
a standard value with:
PdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.A4
or a custom value with:
PdfConverter.PdfDocumentOptions.PdfPageSize = PdfPageSize.Custom
PdfConverter.PdfDocumentOptions.CustomPdfPageSize = new SizeF(widthInPoints, heightInPoints)
With the PDF Creator for .NET library you can set the PDF page size to a standard
value with:
Document.Pages.AddNewPage(PageSize.A4,
new Margins(10,10,0, 0), PageOrientation.landscape)
or a custom value with:
Document.Pages.AddNewPage(new PageSize(widthInPoints, widthInPoints), new Margins(10,10,0,
0), PageOrientation.landscape)
HTML to PDF Converter
Virtual Display
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.
For the PDF Creator you can specify the virtual display width and height by specifying
the htmlViewerWidth and htmlViewerHeight parameters of the HtmlToPdfElement.
By default the virtual display width 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.
HTML Content Resizing in PDF Page
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.
The property FitWidth was added to the PdfConverter.PdfDocumentOptions and to the
HtmlToPdfElement. 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 as described in a section above. 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.
A new property PdfConverter.PdfDocumentOptions.AutoSizePdfPage was added to control
the PDF page width. It 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 can appear as not centered in the PDF page 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.
Single PDF Page Conversion
Starting with version 3.8, the HTML to PDF Converter offers the possibility to produce
the whole HTML content into a single PDF page automatically resized to display the
whole content. To get this behavior you have to set the PdfConverter.PdfDocumentOptions.SinglePage
property on true. When FitWidth is also tru the PDF page width will be preserved,
otherwise the PDF page width will be automatically resized to display the whole
HTML content.
|