Click or drag to resize
Pdf Library for .NET

Pdf Html Element

HTML content can be added to a pdf document in several ways. If a complex document is created that will contain several types of pdf elements and the html content that will be added is only a small part of the total content, PdfHtmlElement objects can be used to convert web pages or raw html content and add the conversion result to the pdf document.

If the pdf is generated mostly as a result of an html to pdf conversion, the HtmlToPdf object should be used instead. This is described in details in the "Html to Pdf Converter" section of our documentation that starts here.

Element properties

Both full web pages and html strings can be converted to pdf using PdfHtmlElement with the appropriate constructor. PdfHtmlElement(String) can be used to convert a full web page specified by an url or local file to pdf. PdfHtmlElement(String, String) can be used to convert a raw html string to pdf.

Properties

AllowContentHeightResize - A flag used only by WebKitRestricted, Blink or Chromium engines indicating if the content height can be recalculated to better fit the page. This can introduce certain errors in some cases. The default is True. Set it to False if content is split to more pages than expected.

Authentication - Handles authentication options if the web page being converted requires authentication.

AutoFitHeight - Specifies the vertical auto fit mode.

AutoFitWidth - Specifies the horizontal auto fit mode.

BlinkEngineLaunchMaxTries - Blink engine process launch tries. Note: This is used only by the Blink rendering engine.

BlinkEngineLaunchTimeout - Blink engine process launch timeout. Note: This is used only by the Blink rendering engine.

BlinkEnginePath - Gets or sets the full path (excluding the chrome.exe file name) of the Blink html rendering engine binaries.

BlinkEngineTemporaryFilesPath - Gets or sets the full path of a folder where Blink html rendering engine will write temporary files. Note: Write permissions need to be enabled for this folder.

BlinkMaxThreadPoolWorkers - Upper bound for the auto-tuned Blink ThreadPool worker floor (prevents browser-launch starvation under concurrency). 0 disables auto-tuning. Note: This is used only by the Blink rendering engine.

CefEnginePath - Gets or sets the full path of the folder containing the CEF (Chromium) html rendering engine binaries. Note: This is used only by the Chromium rendering engine.

CefEngineTemporaryFilesPath - Gets or sets the full path of a folder where the CEF rendering engine will write temporary files. Note: This is used only by the Chromium rendering engine.

ClickElementsDelayAfter - Delay in miliseconds, after element click. Note: This is used only by the Blink or Chromium rendering engine.

ClickElementsDelayBefore - Delay in miliseconds, before element click. Note: This is used only by the Blink or Chromium rendering engine.

ClickElementsSelectors - Specifies elements from the web page that will be clicked before converting the page. Note: This is used only by the Blink or Chromium rendering engine.

ConsoleLog - Returns the console log of the browser used to render the web page.

CssMediaType - Indicates what css styles are used when the web page is rendered.

CustomCSS - Use this property to specify some CSS styles that will be injected into the page that is converted. Note: This is used only by the Blink or Chromium rendering engine.

DenyLocalFileAccess - A flag indicating if local files can be loaded during the conversion. The default value is False and local files can be loaded.

DisplayCutText - Gets or sets a flag indicating if the text that is out of the calculated rendering rectangle is displayed or not. The default value for this property is False.

DisplayFooterOnEvenPages - Controls the visibility of the document footer on the even numbered pages generated by this pdf element.

DisplayFooterOnOddPages - Controls the visibility of the document footer on the odd numbered pages generated by this pdf element.

DisplayHeaderOnEvenPages - Controls the visibility of the document header on the even numbered pages generated by this pdf element.

DisplayHeaderOnOddPages - Controls the visibility of the document header on the odd numbered pages generated by this pdf element.

DrawBackground - Gets or sets a flag indicating if the web page background is rendered in pdf.

EmbedFonts - Instructs the converter to embed all the needed fonts into the pdf document or not. The default value for this property is false and the fonts are not automatically embedded.

ExternalBrowserEndpoint - External browser service. Note: This is used only by the Blink rendering engine.

ExternalLinksEnabled - Controls the rendering of external hyperlinks in pdf. The default value for this property is true and in this case all external hyperlinks from the web page will be rendered in the generated pdf document.

HiddenWebElements - Gets a reference to the object that controls the visibility of some web elements in the generated pdf document.

HttpCookies - Gets the collection of custom HTTP cookies used for the conversion.

HttpHeaders - Get the collection of custom HTTP headers used for the conversion.

HttpPostParameters - Gets the collection of custom HTTP POST parameters used for the conversion.

InternalLinksEnabled - Controls the conversion of internal html links to internal pdf links. The default value for this property is true and in this case all internal hyperlinks from the web page (links that point within the web page) will be rendered in the generated pdf document as internal pdf links (clicking one of them will jump within the pdf document).

JavaScriptEnabled - Enable scripts when rendering the url or html string.

KeepImagesTogether - This property instructs the converter whether to try to avoid cutting off the images between pdf pages or not.

KeepTextsTogether - This property instructs the converter whether to try to avoid cutting off the text lines between pdf pages or not.

LazyImagesLoadingDelay - Delay per page, in miliseconds, for lazy images loading. The default value is 50 ms. Note: Honored by the Blink and Chromium rendering engines.

LazyImagesLoadingEnabled - Enables a delay mechanism to allow images to fully load. Note: Honored by the Blink and Chromium rendering engines.

LoginOptions - Handle custom page login. Note: This is used only by the Blink or Chromium rendering engine.

ManagedContentTrimming - Gets or sets whether the library decides where the rendered content ends on each page. The default value is True. With True, the page the content ends on is drawn only down to where the content ends; an element with an automatic height placed part-way down a page starts in the room left below it and continues on full pages, and a height taller than that room continues on the pages that follow until that much height has been drawn. With False, the page is shortened to the content only when the whole content fits on one page, and an element placed part-way down a page draws only what fits in the room left. Set it to False if pages are cut in the wrong place. Note: This is used only by the Chromium rendering engine.

ManagedContentTrimmingMode - Gets or sets how the rendering engine reports where the rendered content ends when ManagedContentTrimming is True. The default value is Ink. With Ink, the engine measures where the last painted content is after the page is rendered, so what the page paints outside its layout, such as a shadow or a positioned decoration, is kept, together with the space the last element leaves below itself. With Marker, the content ends where the page's layout ends, the way earlier versions cut; something painted outside the layout can be cut. Only the last page is affected: the pages before it are the same in both modes. An engine that does not support the Ink mode uses the Marker mode. Note: This is used only by the Chromium rendering engine.

MaxConversionTime - Timeout in seconds for the print phase. Applies to the Chromium rendering engine only. Default value is 60 seconds.

MaxPageLoadTime - The web page navigation timeout in seconds.

MinPageLoadTime - An additional time in seconds to wait for asynchronous items to be loaded before the web page is rendered.

PageBreaksEnhancedAlgorithm - Gets or sets a flag indicating if an enhanced custom page breaks algorithm is used. The enhanced algorithm is a little bit slower but it will prevent the appearance of hidden text in the PDF when custom page breaks are used. The default value for this property is False.

PdfBookmarkOptions - Gets a reference to the object that controls the bookmarks creation for the generated pdf document.

PdfPagesRectangles - The size and position of the html content rendered in all pages of the pdf document.

PluginsEnabled - A flag indicating if plugins (like Flash players) are enabled in the converter. The default value for this property is true.

PostLoadingScript - Use this property to specify some JavaScript code that will be injected into the page that is converted and executed after the page was fully loaded. Note: This is used only by the Blink or Chromium rendering engine.

PostLoadingScriptDelayAfter - Delay in miliseconds, after post page loading javascript injection. Note: This is used only by the Blink or Chromium rendering engine.

ProxyOptions - Gets a reference to an object containing the proxy settings used to access the web page that is being converted.

RenderPageOnTimeout - A flag indicating if the page is rendered even if a navigation timeout occurs. The default value is False and a navigation timeout exception is raised.

RenderingEngine - Gets or sets the rendering engine used to load and render the html. The default value is WebKit. See Rendering Engines.

ScaleImages - A flag indicating if the images from the page are scaled during the conversion process. The default value is False and images are not scaled.

SecureProtocol - Protocol used for secure (HTTPS) connections.

StartupMode - Use this property to specify how the conversion starts.

StartupScript - Use this property to specify some JavaScript code that will be injected into the page that is converted.

Tagged - Produce tagged, accessible (PDF/UA-style) logical structure from this HTML element's rendered content. The structure is taken from the rendering engine's own tagged output and re-mapped onto the host document as the element is stamped, exactly like the HtmlToPdf converter's Options.Tagged. The default value is False.

VisibleWebElementSelector - Convert only the part of the page matched by this CSS selector, for example "#content", ".infobox" or "table.data tbody". Note: Honored by the Blink and Chromium rendering engines; the WebKit engines take an element id instead.

VisibleWebElementId - Use this property to convert only a certain section of the page, specified by the html element ID. Available with all four rendering engines - see Partial Page Conversion. Honored by every rendering engine; the WebKit engines take only this form.

WebGlEnabled - Controls WebGL support in the rendering engine. The default value is False, which makes the conversion noticeably faster. Set it to True for pages whose content is drawn with WebGL. Honored by the Chromium and Blink rendering engines, starting with v26.4. See Chromium Engine.

WebPageFixedSize - Controls whether the web page is rendered with a fixed size internal browser or the size automatically extends to make the whole content visible.

WebPageHeight - Gets or sets the height of the converted web page as it would appear in the internal browser used to render the html.

WebPageInformation - Gets an object populated after conversion with the title, keywords and description of the converted web page.

WebPageWidth - Gets or sets the width of the converted web page as it would appear in the internal browser used to render the html.

Sample Code

Sample code that shows how to use PdfHtmlElement object to convert a web page to pdf.

// create a new pdf document
PdfDocument doc = new PdfDocument();

// add a new page to the document
PdfPage page = doc.AddPage();

// create html element 
PdfHtmlElement html = new PdfHtmlElement(TxtUrl.Text);

// add the html element to the document
page.Add(html);

// save pdf document
doc.Save(Response, false, "Sample.pdf");

// close pdf document
doc.Close();
See Also