I have tested iTextsharp and iText7 for HTML to PDF conversion. Based on the performance iTextsharp is taking 3 minutes for 10000 PDF creation. But iText7 taking 17 minutes for 10000 PDF creation. Since iText7 is new Version compared to iTextsharp,i decided to use iText7 for Commercial Purpose. But Performance wise iText7 is Low.So Please Tell me How to improve performance of HTML to PDF conversion in iText7?
Testing in iText7
For i As Integer = 0 To 10000
HTML = ReadFile '=> Read HTML file from particular location
'HTML = Replace(HTML) => To Replace the content dynamically
Dim writer As PdfWriter
Dim array() As Byte = System.Text.Encoding.ASCII.GetBytes("a")
writer = New PdfWriter(FileName, New WriterProperties().SetStandardEncryption(array, array, EncryptionConstants.ALLOW_PRINTING,
EncryptionConstants.ENCRYPTION_AES_256))
HtmlConverter.ConvertToPdf(HTML, writer)
Next
Testing In iTextSharp
Imports iTextSharp.text
Imports iTextSharp.text.pdf
Imports iTextSharp.pdfa
Imports System.IO
Imports iTextSharp.text.html.simpleparser
Imports System.Text
Imports iTextSharp.tool.xml.html
Imports iTextSharp.tool.xml
Imports iTextSharp.tool.xml.pipeline.html
For i As Integer = 0 To 10000
HTML = ReadFile '=> Read HTML file from particular location
'HTML = Replace(HTML) => To Replace the content dynamically
Dim bPDF As Byte()
Dim ms As New MemoryStream
Dim doc As Document
doc = New Document(PageSize.A4, 25, 25, 25, 25)
Dim txtReader As New StringReader(Html)
Dim oPdfWriter As PdfWriter
oPdfWriter = PdfWriter.GetInstance(doc, ms)
oPdfWriter.SetEncryption(iTextSharp.text.pdf.PdfWriter.ENCRYPTION_AES_128, "q", "a", 2)
Dim htmlWorker As New HTMLWorker(doc)
doc.Open()
htmlWorker.StartDocument()
htmlWorker.Parse(txtReader)
htmlWorker.EndDocument()
htmlWorker.Close()
doc.Close()
bPDF = ms.ToArray()
Dim FIleName As String = "D:\ItextSharp_" & Now.ToString("ddMMyyyyHHMMssffffff") & ".pdf"
File.WriteAllBytes(FIleName, bPDF)
Next
Function ReadFile()
Dim stringReader As String = ""
Dim objReader As New System.IO.StreamReader("D:\AS1-Revamp\TestHTML\test.html")
Do While objReader.Peek() <> -1
stringReader = stringReader & objReader.ReadLine() & vbNewLine
Loop
ReadFile = stringReader
End Function
I used the above Code to test performance...iText7 Tacking More time to place the pdf file in mentioned Path Compared to iTextSharp.
EDIT: copy/paste of the HTML in that other question:
Based on My Question in the path iText7 Performance Issue Compared With iTextSharp I Have Sent HTML File For MR.Amedee Van Gasse. So Please Tell me How to Improve Performance of iText7..
<div id = "headerdiv" style="width:540px; float:left; background:#ededed; padding:30px; overflow:hidden;">
<br>
<br>
<br>
<div>
<img border='0' src='D:\AS1-Revamp\TestHTML\newlog.bmp' width='100' height='40'>
</div>
<p style="color:Red;align=center;" > Details</p>
<br>
<br>
<table >
<tr border='0'>
<td bgcolor='Green'>
<font size="3" color="white">
SDetails
</font>
</td>
</td>
</tr>
<tr border='0'>
<td>
<div id="dvKYC">
<table border='1'>
<tr>
<td><#lsName#></td>
<td>No:<#lsno#></td>
</tr>
<tr border='1'>
<td width=500><#lsAddess#></td>
<td></td>
</tr>
<tr>
<td><#lsContacts#></td>
<td> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<br>
<div >
<table >
<tr border='0'>
<td bgcolor='Green'>
<font size="3" color="white">
Status
</font>
</td>
</td>
</tr>
</table>
<table style="width:100%;">
<tr bgcolor=gray >
<td style="width:30%;text-align: left; font-weight: bold;">UUH </td>
<td style="width:20%;text-align: left; font-weight: bold;">PN</td>
<td style="width:20%;text-align: left; font-weight: bold;">KC </td>
<td style="width:20%;text-align: left; font-weight: bold;">CC</td>
</tr>
<tr>
<td style"width:200px;"><#lsHs#></td>
<td ><#lsPN#></td>
<td><#lsKC#></td>
<td><#lsCC#></td>
</tr>
</table>
</div>
<div >
<table >
<tr border='0'>
<td bgcolor='Green'>
<font size="3" color="white">
STD
</font>
</td>
</td>
</tr>
</table>
<##TT##>
</div>
After i have Applied Following code two Error Comes in ConverterProperties
1.setCreateAcroForm is not a member of iText.Html2pdf.ConverterProperties
2.setOutlineHandler is not a member of iText.Html2pdf.ConverterProperties
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim converterProperties As ConverterProperties = New ConverterProperties
With converterProperties
.SetBaseUri(".")
.setCreateAcroForm(False)
.SetCssApplierFactory(New DefaultCssApplierFactory())
.SetFontProvider(New DefaultFontProvider())
.SetMediaDeviceDescription(MediaDeviceDescription.CreateDefault())
.setOutlineHandler(New OutlineHandler())
.SetTagWorkerFactory(New DefaultTagWorkerFactory())
End With
Dim HTML = ReadFile("Input_Template")
For i = 0 To 10000
LicenseKey.LoadLicenseFile("C:\iText7\itextkey-0.xml")
Dim PDF = "E:\iText\testpdf " & i & ".pdf"
Dim m As New MemoryStream
Dim writer As PdfWriter
Dim array() As Byte = System.Text.Encoding.ASCII.GetBytes("a")
writer = New PdfWriter(PDF, New WriterProperties().SetStandardEncryption(array, array, EncryptionConstants.ALLOW_PRINTING,
EncryptionConstants.ENCRYPTION_AES_256))
HtmlConverter.ConvertToPdf(HTML, writer, converterProperties)
Next
End Sub
If i Comment That two Lines of code and running my program an Error comes in the line of converter Code i.e(HtmlConverter.ConvertToPdf(HTML, writer, converterProperties))
The Error is:"Pdf indirect object belongs to other PDF document. Copy object to current pdf document."
since coverterproperties is in out of loop this error comes. if i put this all properties within the loop it works fine...but is this correct for performance wise..?
Please Help me for these Three Errors..?