Resizing Output

EO.Pdf HTML to PDF converter can automatically resize the PDF output based on various factors. This section covers the following topic:

Auto Fit Mode

By default, HtmlToPdfOptions's AutoFitX is set to HtmlToPdfAutoFitMode.ShrinkToFit, which instructs the HTML to PDF converter to automatically shrink a Web page to fit the PDF page if the Web page is wider than the PDF page.

For example, if a Web page is 10 inches wide but the available output area (paper size excluding page margins) is only 6.5 by 9 inches (standard letter size paper with 1 inch margin), then the converter will try to shrink the original Web page to 65% of its original size when AutoFitX is set to ShrinkToFit so that the full Web page will fit on the paper. As shown in the following picture:

The above PDF is rendered with AutoFitX set to ShrinkToFit. As a result, all contents are visible even though the Web page is wider than the available output area width.

When AutoFitX is set to None, the converter will not try to shrink the Web page, this causes the right side of the page to be clipped off, as shown in the following picture:

The above PDF is rendered with AutoFitX set to None. As a result, contents exceeding the page's OutputArea are clipped off.

In addition to ShrinkToFit option, AutoFitX also supports ScaleToFit option. While ShrinkToFit option only shrinks the HTML page if the HTML page is wider than the output area, ScaleToFit can shrink or expand the HTML page so that it fits exactly into the output area.

AutoFitY is similar to AutoFitX but is applied vertically. AutoFitY is used much less frequently than AutoFitX because once AutoFitY is set, the whole PDF output will be on a single page.

It is important to understand that the HTML to PDF converter considers both AutoFitX and AutoFitY to decide a single final scale factor, which applies both horizontally and vertically. For example, if both AutoFitX and AutoFitY are set to ScaleToFit and,

  1. The HTML page is twice as wide as the PDF output area;
  2. The HTML page height is only half of the PDF output area;

Then the final scale factor will be 0.5 so that the whole HTML page is shrunk to half of its original size by 50% both horizontally and vertically (as oppose to shrinking horizontally and expanding vertically).

Manual Zoom Level

In addition to AutoFitX and AutoFitY, you can also manually set HtmlToPdfOptions.ZoomLevel to specify a zoom level. The default value for this property is 1, which represents a 100% zoom level. You can use this property to shrink (less than 1) or expand (greater than 1). When this property is set, it is combined with the automatic zoom level based on AutoFitX and AutoFitY settings.

Note: Setting HtmlToPdfOptions.ZoomLevel to a value less than 1 has the effect of increasing the "window" size of the HTML to PDF converter. The default "window" size is the same as the output paper size. For example, if the output paper size is 6.5 inch wide (8.5 inch full width excluding one inch margin on both sides) and the system DPI value is 96, then the default output window size would be 6.5 * 96 = 624 pixels wide. However if ZoomLevel is 0.75, then the default output window size becomes 6.5 * 96 / 0.75 = 832 pixels.

Applying the Same Zoom Level Across Multiple Conversions

Sometimes it is necessary to apply the same zoom level across multiple conversions. Such as:

  • You call ConvertUrl or ConvertHtml multiple times for different sections and they all output to the same result PDF file with one section following each other;
  • You call ConvertHtml to add additional information to each page (such as header and footer) after generating the main contents;

In such cases the first ConvertUrl/ConvertHmtl can determine the zoom level, and all subsequent conversions should use the same zoom level as automatically applied by the first conversion. You can call HtmlToPdfOptions.SyncZoomLevel to achieve this. For example:

//The result PdfDocument object
PdfDocument doc = new PdfDocument();

//Perform the first conversion
HtmlToPdfResult result = HtmlToPdf.ConvertUrl(url1, doc);

//Perform the second conversion, using the same zoom
//level as applied by the first conversion
HtmlToPdf.Options.SyncZoomLevel(result);
HtmlToPdf.ConvertUrl(url2, doc);

//Perform another conversion, still using the same zoom
//level as applied by the first conversion
HtmlToPdf.Options.SyncZoomLevel(result);
HtmlToPdf.ConvertUrl(url3, doc);

DPI Adjustment

EO.Pdf can automatically adjusts output based on your system's DPI settings. The default DPI value is 96 pixels per inch; however this value changes when you change your system's display font size. When the system DPI value increases, contents on screen would appear smaller because the same are can display more pixels. To mimic the same result in the PDF file, you can set HtmlToPdfOptions.AutoAdjustForDPI to true.