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");
Response.Cache.SetCacheability(HttpCacheability.Private);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlMarkData.RenderControl(hw);
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);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
}
Below line of code is important when working with pdf over https
System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
hope this helps some one