EVO HTML to PDF Converter allows you to set various options to control the HTML content scaling in PDF pages. The most important options controlling the HTML content scaling are enumerated below, grouped in a few categories.
HTML Page to Convert
HTML Page URL or Local File to Convert. The URL of the HTML page to convert must be accessible from the computer where the converter runs. If the page requires authentication or if you are using a proxy server to access Internet then you have to set the converter properties accordingly as described in documentation. The method you can use to convert an URL to PDF is HtmlToPdfConverterConvertUrl(String)
HTML Viewer Options
HTML Viewer Width. This option is the equivalent in converter of the browser window width. The property you can set in your code to control the browser window width is HtmlToPdfConverterHtmlViewerWidth. When the browser window width is changed the HTML content displayed inside the window can have a different layout and something similar happens when you change the HTML Viewer width of the converter. At a given viewer width, the converter will capture by default the whole height of the HTML content, but you can set the HTML Viewer height to capture only the top part of the HTML page
HTML Viewer Height. This option is the equivalent in converter of the browser window height and can be used to limit the conversion to the top part of the HTML page. If this property is not set the entire page will be converted. The property you can set in your code to control the browser window height is HtmlToPdfConverterHtmlViewerHeight
HTML Viewer Zoom. The HTML viewer zoom percentage in HTML to PDF Converter similar to zoom level in a browser. The default value of this property is 100. The property you can set in your code to control the zoom level is HtmlToPdfConverterHtmlViewerZoom
Clip HTML Content Width. You can set this option to force the HTML content width to be exactly HtmlToPdfConverterHtmlViewerWidth pixels. If this option is false then actual HTML content width can be larger than HtmlViewerWidth pixels in case the HTML page cannot be entirely displayed in the given viewer width. By default this option is false and the HTML content is not clipped. The property you can set in your code for this option is HtmlToPdfConverterClipHtmlView
PDF Page Options
PDF Page Size. You can set the page size of the generated PDF document to a standard size like A4, Letter, Legal, etc. or you can set custom PDF page size giving the width and height in points. 1 point is 1/72 inches. By default the PDF page size is A4. The property you can set in your code to control the PDF page size is PdfDocumentOptionsPdfPageSize. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
PDF Page Orientation. You can set the page orientation of the generated PDF document to Portrait or to Landscape. By default the page orientation is Portrait. The property you can set in your code to control the PDF page orientation is PdfDocumentOptionsPdfPageOrientation. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
PDF Page Margins. You can individually set the left, right, top and bottom page margins of the generated PDF document. The margins are expressed in points. 1 point is 1/72 inches. By default the PDF page margins are all 0 points. The properties you can set in your code to control the PDF page margins are PdfDocumentOptionsLeftMargin, PdfDocumentOptionsRightMargin, PdfDocumentOptionsTopMargin and PdfDocumentOptionsBottomMargin. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
HTML Content Destination in PDF
HTML Content Destination in PDF. The HTML content destination is given by the X and Y coordinates where to start rendering in first PDF page and by the destination rectangle width and height. All the values are expressed in points. 1 point is 1/72 inches. If you don't set any destination rectangle then by default the converter will start rendering in the top left corner of the first page, will try to use the entire PDF page width for rendering and will auto determine the destination rectangle height such that the entire HTML content is visible. The properties you can set in your code to control the HTML content destination in PDF are PdfDocumentOptionsX, PdfDocumentOptionsY, PdfDocumentOptionsWidth and PdfDocumentOptionsHeight. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
HTML Content Top and Bottom Spacing. Using these options you can set a top and a bottom padding for the HTML content. This can be useful for example when you want to introduce a spacing between the PDF page header or footer and the main content. The properties you can set in your code to control the top and bottom spacing are PdfDocumentOptionsTopSpacing and PdfDocumentOptionsBottomSpacing. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
Scaling Options
Fit Width Option. Use this option to instruct the converter to fit the HTML content width in PDF page width or in the given destination rectangle width. By default this option is true and the HTML content can be resized to fit the PDF page width. The property you can set in your code for this option is PdfDocumentOptionsFitWidth. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
Stretch to Fit Width Option. Use this option to enable the HTML content stretching when its width is smaller than PDF page width. It has effect only when Fit Width option is true. By default this option is false and the HTML content is not stretched. The property you can set in your code for this option is PdfDocumentOptionsStretchToFit. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
Auto Size PDF Page Option. Use this option to automatically dimension the PDF page to display the HTML content unscaled. It has effect only when the Fit Width option is false. By default this option is true and the PDF page is automatically dimensioned when Fit Width option is false. The property you can set in your code for this option is PdfDocumentOptionsAutoSizePdfPage. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
Fit Height Option. Use this option to fit the HTML content height in PDF page height or in the given destination rectangle height. If both Fit Width and Fit Height are true then the HTML content will resized if necessary to fit both width and height preserving the aspect ratio at the same time. By default this option is false and the HTML content is not resized to fit the PDF page height. The property you can set in your code for this option is PdfDocumentOptionsFitHeight. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
Single PDF Page Option. Use this option to render the whole HTML content into a single PDF page. The PDF page size is limited to 14400 points. By default this options is false. The property you can set in your code for this option is PdfDocumentOptionsSinglePage. An object of PdfDocumentOptions type is exposed by the HtmlToPdfConverterPdfDocumentOptions property
protected void convertToPdf() { // Get the server IP and port String serverIP = textBoxServerIP.Text; uint serverPort = uint.Parse(textBoxServerPort.Text); // Create a HTML to PDF converter object HtmlToPdfConverter htmlToPdfConverter = null; if (radioButtonUseTcpService.Checked) htmlToPdfConverter = new HtmlToPdfConverter(serverIP, serverPort); else htmlToPdfConverter = new HtmlToPdfConverter(true, textBoxWebServiceUrl.Text); // Set optional service password if (textBoxServicePassword.Text.Length > 0) htmlToPdfConverter.ServicePassword = textBoxServicePassword.Text; // Set license key received after purchase to use the converter in licensed mode // Leave it not set to use the converter in demo mode htmlToPdfConverter.LicenseKey = "4W9+bn19bn5ue2B+bn1/YH98YHd3d3c="; // Set an adddional delay in seconds to wait for JavaScript or AJAX calls after page load completed // Set this property to 0 if you don't need to wait for such asynchcronous operations to finish htmlToPdfConverter.ConversionDelay = 2; // Html Viewer Options // Set HTML Viewer width in pixels which is the equivalent in converter of the browser window width // This is a preferred width of the browser but the actual HTML content width can be larger in case the HTML page // cannot be entirely displayed in the given viewer width // This property gives the size of the HTML content which can be further scaled to fit the PDF page based on selected options // The HTML content size is in pixels and the PDF page size is in points (1 point = 1/72 inches) // The converter is using a 96 DPI resolution to transform pixels to points with the following formula: Points = Pixels/96 * 72 htmlToPdfConverter.HtmlViewerWidth = int.Parse(htmlViewerWidthTextBox.Text); // Set HTML viewer height in pixels to convert the top part of a HTML page // Leave it not set to convert the entire HTML if (htmlViewerHeightTextBox.Text.Length > 0) htmlToPdfConverter.HtmlViewerHeight = int.Parse(htmlViewerHeightTextBox.Text); // Set the HTML content clipping option to force the HTML content width to be exactly HtmlViewerWidth pixels // If this option is false then the actual HTML content width can be larger than HtmlViewerWidth pixels in case the HTML page // cannot be entirely displayed in the given viewer width // By default this option is false and the HTML content is not clipped htmlToPdfConverter.ClipHtmlView = clipContentCheckBox.Checked; // Set the HTML content zoom percentage similar to zoom level in a browser htmlToPdfConverter.HtmlViewerZoom = int.Parse(htmlViewerZoomTextBox.Text); // PDF Page Options // Set PDF page size which can be a predefined size like A4 or a custom size in points // Leave it not set to have a default A4 PDF page htmlToPdfConverter.PdfDocumentOptions.PdfPageSize = SelectedPdfPageSize(); // Set PDF page orientation to Portrait or Landscape // Leave it not set to have a default Portrait orientation for PDF page htmlToPdfConverter.PdfDocumentOptions.PdfPageOrientation = SelectedPdfPageOrientation(); // Set PDF page margins in points or leave them not set to have a PDF page without margins htmlToPdfConverter.PdfDocumentOptions.LeftMargin = float.Parse(leftMarginTextBox.Text); htmlToPdfConverter.PdfDocumentOptions.RightMargin = float.Parse(rightMarginTextBox.Text); htmlToPdfConverter.PdfDocumentOptions.TopMargin = float.Parse(topMarginTextBox.Text); htmlToPdfConverter.PdfDocumentOptions.BottomMargin = float.Parse(bottomMarginTextBox.Text); // HTML Content Destination and Spacing Options // Set HTML content destination in PDF page if (xLocationTextBox.Text.Length > 0) htmlToPdfConverter.PdfDocumentOptions.X = float.Parse(xLocationTextBox.Text); if (yLocationTextBox.Text.Length > 0) htmlToPdfConverter.PdfDocumentOptions.Y = float.Parse(yLocationTextBox.Text); if (contentWidthTextBox.Text.Length > 0) htmlToPdfConverter.PdfDocumentOptions.Width = float.Parse(contentWidthTextBox.Text); if (contentHeightTextBox.Text.Length > 0) htmlToPdfConverter.PdfDocumentOptions.Height = float.Parse(contentHeightTextBox.Text); // Set HTML content top and bottom spacing or leave them not set to have no spacing for the HTML content htmlToPdfConverter.PdfDocumentOptions.TopSpacing = float.Parse(topSpacingTextBox.Text); htmlToPdfConverter.PdfDocumentOptions.BottomSpacing = float.Parse(bottomSpacingTextBox.Text); // Scaling Options // Use this option to fit the HTML content width in PDF page width // By default this property is true and the HTML content can be resized to fit the PDF page width htmlToPdfConverter.PdfDocumentOptions.FitWidth = fitWidthCheckBox.Checked; // Use this option to enable the HTML content stretching when its width is smaller than PDF page width // This property has effect only when FitWidth option is true // By default this property is false and the HTML content is not stretched htmlToPdfConverter.PdfDocumentOptions.StretchToFit = stretchCheckBox.Checked; // Use this option to automatically dimension the PDF page to display the HTML content unscaled // This property has effect only when the FitWidth property is false // By default this property is true and the PDF page is automatically dimensioned when FitWidth is false htmlToPdfConverter.PdfDocumentOptions.AutoSizePdfPage = autoSizeCheckBox.Checked; // Use this option to fit the HTML content height in PDF page height // If both FitWidth and FitHeight are true then the HTML content will resized if necessary to fit both width and height // preserving the aspect ratio at the same time // By default this property is false and the HTML content is not resized to fit the PDF page height htmlToPdfConverter.PdfDocumentOptions.FitHeight = fitHeightCheckBox.Checked; // Use this option to render the whole HTML content into a single PDF page // The PDF page size is limited to 14400 points // By default this property is false htmlToPdfConverter.PdfDocumentOptions.SinglePage = singlePageCheckBox.Checked; string url = urlTextBox.Text; // Convert the HTML page to a PDF document using the scaling options byte[] outPdfBuffer = htmlToPdfConverter.ConvertUrl(url); }