Hi,
Currently,
I am evaluating HTML to PDF conversion using Aspose.PDF 7.2. Below are the
couple of requirements which we would like to take in to consideration.
- 1. Image & CSS Support during
conversion
- 2. Tables & Input Controls Support.
- 3. Page Breaking (In case when rendered
HTML has scrollbar in it. It should page break accordingly when HTML is long
enough.)
Could you
let us know which the recommended way to achieve above mentioned requirements.
Moreover,
below are the couples of approaches we have tried out with attached HTML pages to
convert it to PDF but none of them succeeded so far. With each approach we are
getting below mentioned exception.
Exception:
An
unhandled exception of type 'System.StackOverflowException' occurred in
mscorlib.dll.
Inner Exception: {Unable to evaluate expression.}
Approach 1 (Using Aspose 7.2): Getting same Exception mentioned above.
Dim a As Byte() = My.Resources.Aspose_Total
Dim m_Stream As MemoryStream = Nothing
Dim pdfDocumentGenerator = New Aspose.Pdf.Generator.Pdf()
Dim modifiedFilePath As String = destPath + "\ResultMultiPageFile" + ".PDF"
Try
Dim memLicense As System.IO.MemoryStream
Dim licPDF As Aspose.Pdf.License = New Aspose.Pdf.License()
memLicense = New System.IO.MemoryStream(a)
licPDF.SetLicense(memLicense)
If Not System.IO.Directory.Exists(destPath) Then
System.IO.Directory.CreateDirectory(destPath)
End If
If System.IO.File.Exists(modifiedFilePath) Then
System.IO.File.Delete(modifiedFilePath)
End If
For Each FilePath As String In FileNames
Dim BasePath As String = System.IO.Path.GetDirectoryName(FilePath)
Dim m_HTMLLoadOption As New Aspose.Pdf.HtmlLoadOptions(BasePath)
Dim PDFDOc As New Aspose.Pdf.Document(FilePath, m_HTMLLoadOption)
PDFDOc.Save(modifiedFilePath)
Next
Catch ex As Exception
Throw ex
Finally
If m_Stream IsNot Nothing Then m_Stream.Dispose()
End Try
Approach 2 (Using Aspose 7.2):
Getting same Exception mentioned above.
Dim a As Byte() = My.Resources.Aspose_Total
Dim m_Stream As MemoryStream = Nothing
Dim pdfDocumentGenerator = New Aspose.Pdf.Generator.Pdf()
Dim modifiedFilePath As String = destPath + "\ResultMultiPageFile" + ".PDF"
Try
Dim memLicense As System.IO.MemoryStream
Dim licPDF As Aspose.Pdf.License = New Aspose.Pdf.License()
memLicense = New System.IO.MemoryStream(a)
licPDF.SetLicense(memLicense)
If Not System.IO.Directory.Exists(destPath) Then
System.IO.Directory.CreateDirectory(destPath)
End If
If System.IO.File.Exists(modifiedFilePath) Then
System.IO.File.Delete(modifiedFilePath)
End If
For Each FilePath As String In FileNames
pdfDocumentGenerator.HtmlInfo.CharSet = "UTF-8"
' load the HTML file to Stream object
pdfDocumentGenerator.BindHTML(System.IO.File.ReadAllText(FilePath))
pdfDocumentGenerator.Save(modifiedFilePath)
Next
Catch ex As Exception
Throw ex
Finally
If m_Stream IsNot Nothing Then m_Stream.Dispose()
End Try
Approach 3 (Using Aspose 7.2):
Getting same Exception mentioned above.
Dim a As Byte() = My.Resources.Aspose_Total
Dim m_Stream As MemoryStream = Nothing
Dim pdfDocumentGenerator = New Aspose.Pdf.Generator.Pdf()
Dim modifiedFilePath As String = destPath + "\ResultMultiPageFile" + ".PDF"
Try
Dim memLicense As System.IO.MemoryStream
Dim licPDF As Aspose.Pdf.License = New Aspose.Pdf.License()
memLicense = New System.IO.MemoryStream(a)
licPDF.SetLicense(memLicense)
If Not System.IO.Directory.Exists(destPath) Then
System.IO.Directory.CreateDirectory(destPath)
End If
If System.IO.File.Exists(modifiedFilePath) Then
System.IO.File.Delete(modifiedFilePath)
End If
For Each FilePath As String In FileNames
' add the section to PDF document sections collection
Dim section As Aspose.Pdf.Generator.Section = pdfDocumentGenerator.Sections.Add()
' Read the contents of HTML file into StreamReader object
'Dim r As StreamReader = File.OpenText(FilePath)
'Create text paragraphs containing HTML text
Dim text2 As Aspose.Pdf.Generator.Text = New Aspose.Pdf.Generator.Text(section, System.IO.File.ReadAllText(FilePath))
' 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
pdfDocumentGenerator.HtmlInfo.ImgUrl = System.IO.Path.GetDirectoryName(FilePath)
Next
pdfDocumentGenerator.Save(modifiedFilePath)
Catch ex As Exception
Throw ex
Finally
If m_Stream IsNot Nothing Then m_Stream.Dispose()
End Try
Could you
suggest recommended way to do this?