Generate PDF from aspx page

Hi,

I am developing a code based on the sample code given by you. The code is as follows.

string WebUrl = HttpContext.Current.Request.Url.ToString(); // http://localhost:8080/sales.aspx

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(WebUrl);

request.Timeout = 10000; // 10 secs

HttpWebResponse localWebResponse = (HttpWebResponse)request.GetResponse();

Encoding encoding = Encoding.GetEncoding(1252);

StreamReader localResponseStream = new StreamReader(localWebResponse.GetResponseStream(), encoding);

Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

Aspose.Pdf.Generator.Section section = pdf.Sections.Add();

Aspose.Pdf.Generator.Text text = new Aspose.Pdf.Generator.Text(section, localResponseStream.ReadToEnd());

text.IsHtmlTagSupported = true;

section.Paragraphs.Add(text);

pdf.HtmlInfo.ImgUrl = “Images”;

pdf.Save(@“C:\DirectHTML2pdf.pdf”);

localWebResponse.Close();

localResponseStream.Close();

It always throwing the errors at pdf.Save. The error is object reference not set to instance of an object.

An early reply with working code is highly appreciated.

Thanks,

Sai

Hi Sai,

Thank you for considering Aspose.Pdf for .NET.

I tried your sample code and it works fine. Please share your aspx file (or create a sample application and upload here) . This will help us reproduce the issue and get back to you soon.

Thank You & Best Regards,

Hi,

Can you please share the source HTML file so that we can test the scenario at our end. We apologize for your inconvenience.