Click or drag to resize
Pdf Library for .NET
Exclude Elements from Conversion

Select.Pdf Html to Pdf Converter for .NET can be used to exclude certain elements from the conversion when a web page is converted to pdf.

The elements that will be excluded are defined using the HiddenWebElements property of the HtmlToPdfOptions object. This is an instance of the HiddenWebElements class, whose single property is CssSelectors.

In other words, the elements that will be excluded are defined using CSS selectors. For example, the selector for all the H1 elements is "H1", the selector for all the elements with the CSS class name 'myclass' is "*.myclass" and the selector for the elements with the id 'myid' is "*#myid". Read more about CSS selectors here.

Sample Code

This sample code shows how the html to pdf converter can exclude all images when the web page is converted to pdf.

// instantiate a html to pdf converter object
HtmlToPdf converter = new HtmlToPdf();

// exclude all images
converter.Options.HiddenWebElements.CssSelectors = new string[] {"img"};

// create a new pdf document converting an url
PdfDocument doc = converter.ConvertUrl(TxtUrl.Text);

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

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