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

Free Support Forum - aspose.com

Convert HTML to PDF failed for large html files

Hi,


I am using Aspose.PDF version 11.2 to convert HTML files to PDF. The below code is working properly for small size of html (50k-80K) but for larger (900k+) it failed and returned error:

Also, my html file includes a reference to the css file.

for larger files the code is crashing on the highlighted line below.

Code:
Dim dataDir As String = Path.GetFullPath("…/…/…/Data/")
Dim filename As String = “data.html”
Dim fileOutPDF As String = “data.pdf”

If File.Exists(dataDir & fileOutPDF) Then
File.Delete(dataDir & fileOutPDF)
End If

Dim Licence As Aspose.Pdf.License = New Aspose.Pdf.License
Licence.SetLicense(“Aspose.Total.lic”)

Dim basePath As String = dataDir
Dim htmloptions As New HtmlLoadOptions(basePath)

’ Load HTML file
Dim pdfDocument As New Document(dataDir & filename, htmloptions)
pdfDocument.PageInfo.Width = 597.6
pdfDocument.PageInfo.Height = 842.4

'get page collection
Dim pageCollection As PageCollection = pdfDocument.Pages
'get particular page
For Each pdfPage As Page In pageCollection
pdfPage.SetPageSize(597.6, 842.4)
Next

'Optimize the pdf file in order to decrease it’s size
Dim optimization As Aspose.Pdf.Document.OptimizationOptions = New Aspose.Pdf.Document.OptimizationOptions()
optimization.LinkDuplcateStreams = True
optimization.RemoveUnusedObjects = True
optimization.RemoveUnusedStreams = True
optimization.CompressImages = True
'optimization.ImageQuality = 10
pdfDocument.OptimizeResources(optimization)

’ Save HTML file
pdfDocument.Save(dataDir & fileOutPDF, SaveFormat.Pdf)

I attached the error for review.
I am not sure if it size limitation or something else.
This is an urgent issue since we deployed the code to production and got error for large files.

Thanks.

In my html files I have some div elements with percentage width size (i.e. width:100%). If the size of html file is not that big the file is converted to PDF properly but once I have a big html file that dynamic percentage is causing the attached error.



Could you please explain why having a dynamic with in css can cause crashing your dll file.

I replaced all the dynamic widths to a fix width but am concern if it is a really fix since I don’t know why it was failing.

I need some answer ASAP to know what features and styles are supported with Aspose.PDF file.

Hi David,


Thanks for contacting support.

Can you please share the resource/input HTML file, so that we can test the scenario in our environment. We are sorry for your inconvenience.