Click or drag to resize

Exclude a HTML Region from Conversion

The converter can be instructed to exclude HTML regions from the generated PDF document like HTML DIVs or tables. The HTML elements to be excluded can be identified by the HTML IDs of the elements or by the HTML tag names of the elements. The HtmlExcludedRegionsOptions property of type HtmlExcludedRegionsOptions is used to specify the excluded regions. The HtmlExcludedRegionsOptions class has three properties that can be used to define the HTML elements excluded by ID, by tag name or using CSS selectors.

public string[] HtmlElementIds { get; set; }
public string[] HtmlTagNames { get; set; }
public string[] HtmlElementSelectors { get; set; }
Sample Code

In the example below the HTML elements with ID "printRegion1" or "printRegion2" and all the "H1" elements will not be rendered in the generated PDF:

pdfConverter.HtmlExcludedRegionsOptions.HtmlElementIds = new string[] { "printRegion1", "printRegion2" };
pdfConverter.HtmlExcludedRegionsOptions.HtmlTagNames = new string[] { "H1" };

The sample code above can be rewritten using CSS selectors (the HtmlElementSelectors property only works when the WebKit rendering engine is used):

pdfConverter.HtmlExcludedRegionsOptions.HtmlElementSelectors = new string[] { "*#printRegion1", "*#printRegion2", "H1" };