1

I have a website which should generate a pdf. The URLs of the images are supplied by a webservice. urls contain https and do not upload my pdf.

How can I fix this?

 iTextSharp.text.Document doc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0);

        var html = string.Format(@"{0}", htmlToConvert);
        StringReader strReader = new StringReader(html);
        System.IO.MemoryStream m = new System.IO.MemoryStream();

        var pdfWriter = PdfWriter.GetInstance(doc, m);           
        doc.Open();           
        iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(pdfWriter, doc, strReader);           
        doc.Close();           
        pdfWriter.Flush();
        pdfWriter.Close();

        HttpResponseBase response = context.HttpContext.Response;
        response.Clear();
        // add the Content-Type and Content-Disposition HTTP headers
        response.AddHeader("Content-Type", "application/pdf");
        response.AddHeader("Content-Disposition", String.Format("attachment; filename=file.pdf; size={0}", m.GetBuffer().Length.ToString()));           
        response.OutputStream.Write(m.GetBuffer(), 0, m.GetBuffer().Length);
        response.OutputStream.Flush();
        response.OutputStream.Close();
        response.End();
VTMLA
  • 11
  • 1
  • What exactly happens when you run this code? – demonkoryu Nov 25 '14 at 16:58
  • 1
    I often see this when a server can't successfully make a secure connection for the resource because sometimes servers aren't allowed to egress on 443 to make these requests. iTextSharp hands this off to the BCL for processing so there really shouldn't be any problems with iTextSharp itself. Can you try making a very simple webpage that uses a `System.Net.WebClient` to download the resourece and see if you get an exceptions. Also, unrelated but instead of `GetBuffer()` use `ToArray()`, see http://stackoverflow.com/a/5119739/231316 – Chris Haas Nov 25 '14 at 20:05

0 Answers0