We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Html to convert to pdf

Hello,

I was trying the .net version of aspose.pdf, and I was trying to render an html page (google page in this case) to .pdf. But when I use pdf.save, it gives me an “Object not set to an instance of an object.”

Here’s my code, am I doing something wrong?

// The address of the web URL which you need to convert into PDF format

string WebUrl = "http://en.wikipedia.org/wiki/Main_Page";

// create a Web Request object to connect to remote URL

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

// set the Web Request timeout

request.Timeout = 10000; // 10 secs

// Retrieve request info headers

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

// Windows default Code Page (Include System.Text namespace in project)

Encoding encoding = Encoding.GetEncoding(1252);

// Read the contents of into StreamReader object

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

// Instantiate an object PDF class

Pdf pdf = new Pdf();

// add the section to PDF document sections collection

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

//Create text paragraphs containing HTML text

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

// enable the property to display HTML contents within their own formatting

text2.IsHtmlTagSupported = true;

// Add the text object containing HTML contents to PD Sections

section.Paragraphs.Add(text2);

// Specify the URL which serves as images database

//pdf.HtmlInfo.ImgUrl = "http://en.wikipedia.org/";

//Save the pdf document

pdf.Save("E:/SunJoy/_2/5.pdf");

localWebResponse.Close();

localResponseStream.Close();

Hi,

Thanks for using our products.

The InLineHTML approach of converting HTML files into PDF format is a workaround and sometimes this approach causes issues with remote websites. However, this approach is comparatively stable when converting offline saved HTML pages into PDF format but still we cannot guarantee 100% stable results. Besides this, we are planning to introduce back the BindHTML(...) method by the month of September and we hope it will be able to convert remote HTML pages into PDF format. Please be patient and wait for the solution.

Your patience and comprehension is greatly appreciated in this regard. We apologize for your inconvenience.