We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Unable to exclude HTML element when converting aspx page to pdf

Thread ID:





151331 Feb 7,2020 05:12 AM UTC Feb 10,2020 08:53 AM UTC ASP.NET Web Forms (Classic) 1
Tags: PDF
Roshandeep Singh Saini
Asked On February 7, 2020 05:12 AM UTC

            <div id="exportButton">
                <asp:Button Width="150px" Style="margin-left: 3px;" data-exclude="true" ID="Button1" Height="27px" runat="server" 
                    OnClick="Button1_Click" Text="Download Report" />

 protected void Button1_Click(object sender, EventArgs e)
            //Initialize HTML to PDF converter 
            HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit);
            WebKitConverterSettings settings = new WebKitConverterSettings();
            //Set WebKit path
            settings.WebKitPath = Server.MapPath("~/QtBinaries");
            //Assign WebKit settings to HTML converter
            htmlConverter.ConverterSettings = settings;
            //Get the current URL
            string url = HttpContext.Current.Request.Url.AbsoluteUri;
            //Convert URL to PDF
            PdfDocument document = htmlConverter.Convert(url);
            //Save the document
            string filename = "Risk_Report" + DateTime.Now.ToString();
            Session["filename"] = filename;
            document.Save(filename+".pdf", HttpContext.Current.Response, HttpReadType.Save);


Need to remove the Div from the pdf that gets downloaded. Kindly assist.

Prakash Viswanathan [Syncfusion]
Replied On February 10, 2020 08:53 AM UTC

Hi Roshandeep, 
Thank you for contacting Syncfusion support.  
You can exclude the HTML element while printing/HTML conversion with print media type CSS. We have attached a simple sample, where the button only visible on screen media type. We need to set the button hide styles in print media type and convert it to PDF with Print media type in the converter settings. Please find the code snippet and styles below, 
Kindly copy the QtBinaries folder from HTML converter NuGet package folder to project folder before performing the conversion. 
Print media: 
//Set print media type 
settings.MediaType = MediaType.Print; 
<style type="text/css"> 
     @media print { 
          #exportButton { 
                display: none; 
<div id="exportButton"> 
     <asp:Button Width="150px" Style="margin-left: 3px;" data-exclude="true" ID="Button1" Height="27px" runat="server" OnClick="Button1_Click" Text="Download Report" /> 
Also, you can convert the particular HTML element by providing the HTML element ID in the Partial HTML conversion. Please refer below link for more information. 
Please let us know if you need any further assistance on this.  
Prakash V 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon