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

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.

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

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

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.

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.

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.

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

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

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

VisibleWebElementId - Use this property to convert only a certain section of the page, specified by the html element ID.

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

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

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.

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

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