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.