Pdf over https, pdf on https, SSL error pdf

CODE to download pdf documents over http is normal. When browsing site from https pdf download will not work and gives SSL errors though PDF will be downloaded by changing internet explorer settings document will not opened. to overcome the issue for pdf download over https binding below is the code to overcome the issue.

PDF attachment code will not work when browsing on https.

Below is the code that works over http as well as https.

using System.IO;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
public class PDFExport
public void exportToPDF()
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=temp.pdf");
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);

StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

Below line of code is important when working with pdf over https

System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

hope this helps some one


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: