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

Free Support Forum - aspose.com

.NET Aspose. Pdf 7.9.0.0 generate empty pdf from Html string

Hi,

I have been tasked to find an easy solution to convert Html pages to Pdf files and your product seemed to be exactly what we needed so I went ahead and tried your exemple here.

Sadly the result was not what I expected as I was presented with a blank Pdf file (with a size of 0Ko) although I only did a simple Copy/Past or your presented solution.

I also tried my own simple implementation

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(PathUrl); request.Timeout = 10000;

Encoding encoding = Encoding.GetEncoding(1252);

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

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

{

Pdf pdfGenerator = new Pdf();

Section section = pdfGenerator.Sections.Add();

Text textGenerator = new Text(section, localResponseStream.ReadToEnd())

{ IsHtmlTagSupported = true };

section.Paragraphs.Add(textGenerator);

pdfGenerator.HtmlInfo.ExternalResourcesBasePath = PathUrl.Substring(0, PathUrl.IndexOf('/', 10) + 1);

pdfGenerator.HtmlInfo.ImgUrl = pdfGenerator.HtmlInfo.ExternalResourcesBasePath;

pdfGenerator.Save(_outputFile);

}

With the almost the same result, some pages giving empty Pdf file (http://www.google.com, http://en.wikipedia.org/wiki/Main_Page), some giving almost the expected result (http://www.w3schools.com/html/default.asp) and some even giving a StackOverflow exception (http://www.neogaf.com/forum/forumdisplay.php?f=2).

Am I doing something horribly wrong, did I miss anything ?

With Visual Studio 2010 SP1, .NET Frameword 4.0, Any CPU, Windows 7 64Bits.

Hi Paillat,


Currently Aspose.Pdf for .NET only supports simple HTML pages and I am afraid complex HTML is not supported. The reason you are getting error while converting certain pages into PDF format might be due to the complexity and structure of source Page. Can you please try converting some offline pages and in case you still face the same issue, please share the source files.

We are sorry for this inconvenience.

Hi, thank you for your response.

I did some more testing with an older version of your library we apparently used at some point in my company (v6.8.0.0) and it seems to behave better. For a start I actually get Exception thrown while v7.9.0.0 was crashing silently (problems seems to be unknown font and whatnot so nothing major as we have control on what is installed on our server and what pages we will import as pdf).

On a side note, when there is exception, Aspose pdf does not seem to release the output file and I have to quit my process so I can delete it (with both versions I am using).

Would there be a way to tell the pdf generator to use the print css ? Since our primary use would be to create pdf of our intranet news, we want the rendering to be as close as possible of what is produced with the xps printer.

Hi Palliat,


Thanks for your feed back. While testing with Aspose.Pdf for .NET 7.9, I’ve manged to observe both issues, empty output and stack overflow exception while converting HTML pages to PDF. I’ve logged following issue in our issue tracking system for further investigation and resolution.

  • PDFNEWNET-34700: Empty output
  • PDFNEWNET-35251: StackOverFlow Exception
Moreover, please check following documentation link for referencing CSS during conversion. Hopefully it will serve the purpose.


Please feel free to contact us for any further assistance.

Best Regards,

The issues you have found earlier (filed as PDFNEWNET-36235) have been fixed in Aspose.Pdf for .NET 9.8.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi,
Thanks for your patience.
We are pleased to share that we have made significant improvements in our HTML to PDF conversion feature in new Document Object Model of Aspose.Pdf namespace and the issue you have reported earlier (filed as PDFNEWNET-34700) has been fixed in Aspose.Pdf for .NET 11.0.0. Please try using the new approach and new release version and in case you still face any issue or you have any further query, please feel free to contact.


(5)

The issues you have found earlier (filed as PDFNEWNET-34700) have been fixed in Aspose.Pdf for .NET 11.5.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.