iTextSharp - Generate PDF file - The remote server returned an error: (407) Proxy Authentication Required

StackOverflow https://stackoverflow.com/questions/20468264

Question

I am facing proxy authentication issue on my below code snipplet.

file = [FILEPATH]
htmlData = [HTML CONTENTS]

System.IO.StringReader objReader = default(System.IO.StringReader);
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = default(HTMLWorker);

objReader = new System.IO.StringReader(htmlData);
FileStream fsTest = new FileStream(file, FileMode.Create, FileAccess.ReadWrite);

htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc, fsTest);

pdfDoc.Open();
htmlparser.Parse(objReader);
pdfDoc.Close();

I am not sure weather it is iTextSharp issue or I need to do some authentication at code level? Please suggest.

Detailed error:

The remote server returned an error: (407) Proxy Authentication Required. || System.Net.WebException: The remote server returned an error: (407) Proxy Authentication Required. at System.Net.HttpWebRequest.GetResponse() at iTextSharp.text.Image.GetInstance(Uri url) at iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, Dictionary`2 h) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) at AppWeb.AssetActions.GeneratePDFFromHTML(String htmlData, String file) || at System.Net.HttpWebRequest.GetResponse() at iTextSharp.text.Image.GetInstance(Uri url) at iTextSharp.text.html.simpleparser.HTMLWorker.StartElement(String tag, Dictionary`2 h) at iTextSharp.text.xml.simpleparser.SimpleXMLParser.Go(TextReader reader) at.
Était-ce utile?

La solution

As I have commented, you should check each url within the htmlData string. You need to make sure each url is accessible without any proxy errors by your .NET assembly. Also search for any parsing tags used by template engines. Here are some that come to my mind:

<? ?> - php
<?php ?> - php
<?= ?> - php
<% %> - asp, asp.net, php
<%= %> - asp, asp.net, php
<< >> - webapp2
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top