Problem while generating PDF from html document

Following is the code I'm using to convert html files into pdf:

//Instantiate License class and call its SetLicense method to use the license
Aspose.Pdf.License license = new Aspose.Pdf.License();

string LicenseFilePath = Server.MapPath("~/") + @"Content\Aspose.Total.lic";
license.SetLicense(LicenseFilePath);

string doc = model.GetHTMLDocument(submissionId);
Byte[] byt = ASCIIEncoding.ASCII.GetBytes(doc);
Stream stream = new MemoryStream(byt);

//Create pdf document
Aspose.Pdf.Generator.Pdf pdf = new Aspose.Pdf.Generator.Pdf();

//Add a section into the pdf document
Aspose.Pdf.Generator.Section sec = pdf.Sections.Add();

Aspose.Pdf.Generator.Text text = new Aspose.Pdf.Generator.Text(sec, doc);

// enable the property to display HTML contents within their own formatting
text.IsHtmlTagSupported = true;

//Add a text paragraph into the section
sec.Paragraphs.Add(text);

pdf.HtmlInfo.ImgUrl = @"D:\";

//open document
Document pdfDocument = new Document(pdf);

//Save the document
pdfDocument.Save("SubmissionPackage.pdf");


This code has few issues like:
1. Though I have set the pdf.HtmlInfo.ImgUrl, images are not appearing in the output pdf.
2. It takes very long to open the document [Document pdfDocument = new Document(pdf);]. Sometimes, I don't even get any response. It seems like stuck into an infinite loop. Not sure about in what scenarios, it gets stuck. File size I'm testing is not more than 2MB, but my requirement is this code should support upto 200MB.

Can someone please help me about this?

Hi Dipak,

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Please share your HTML file (with source images) with us so we can test your reported issues regarding missing images and performance of the conversion process.

Thank You & Best Regards,

Hi Nausherwan,


Thanks for the reply.
Attached is the string I get by code ‘string doc = model.GetHTMLDocument(submissionId);’. The output pdf is supposed to display all contents in the attached file.

Hi Dipak,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the file.

However, when I tried to test the file, I got "Value cannot be null.\r\nParameter name: name" exception with the latest version of Aspose.Pdf for .NET v7.4. I checked the file in the text editor and I noticed a lot of \t\t\t and \n\r elements in the HTML file which may be causing this problem. Please confirm if you have a similar HTML file at your end and do you face a similar issue with the latest version? If not then please share the proper contents of HTML file/string which we can test to reproduce your issue.

Sorry for the inconvenience,

Nausherwan,

Actually the html file I am using is the output of Aspose conversion of word document to html. You would be able to see the meta tags inserted by aspose. I’m doing few customization over the converted html, but I’m sure that these \t\t\t and \n\r are not added by that customization.

I will try removing these characters from the html and try generating pdf. But it would be really helpful if you can provide a set of such characters which might cause pdf generation to stall.

Thanks a lot again for your reply.

I tried replacing the characters, ‘/r’, ‘/n’, ‘/t’ but no luck :frowning:

It is not able to create the pdf and application hangs on the same line of code.

Hi Dipak,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for the feedback.

I would suggest you to create a sample application and share with us (including your complete process). This will help us reproduce your issue and rectify it.

Also, Word to PDF conversion feature of Aspose.Words can be used as well, if that fits your needs.

Sorry for the inconvenience,