-
Jul 24th, 2021, 09:53 AM
#1
Thread Starter
New Member
ITextSharp - Different performance between file reading and TIFF page reading
Hello, I'm anticipating that the programming for me is in its infancy, so I expose a problem maybe trivial but for me inexplicable.
I have created a simple SUB that calls a function for all the TIF files contained in a folder, passing it the full path (e.g. c:\test\1.tif) and only the name (e.g. 1.tif).
Each TIF contains 2 sides
The function processes all files and converts them to PDF with iTextSharp version 5.3.0.
https://www.nuget.org/packages/iTextSharp/5.3.3
vb.net Code:
Sub SurroundingSub3(FullName As String, Name As String)
Dim Document As New iTextSharp.text.Document()
Dim FirstPage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(FullName)
Dim MyX As Double = FirstPage.ScaledWidth / 100 * 24
Dim MyY As Double = FirstPage.ScaledHeight / 100 * 24
FirstPage.ScaleToFit(MyX, MyY)
FirstPage.SetAbsolutePosition(0, 0)
Dim FirstPageSize As New iTextSharp.text.Rectangle(MyX, MyY)
Document.SetPageSize(FirstPageSize)
Dim pdfFILE As String = Application.StartupPath & "" & Name & ".pdf"
Dim DocumentWriter As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(Document, New IO.FileStream(pdfFILE, IO.FileMode.Create)) 'Inizializza il PDF
Document.Open()
Dim myImage As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(FullName)
myImage.ScaleToFit(MyX, MyY)
myImage.SetAbsolutePosition(0, 0)
Dim PageSize As New iTextSharp.text.Rectangle(MyX, MyY)
Document.SetPageSize(PageSize)
Document.Add(myImage)
Document.NewPage()
Document.Close()
End Sub
This code processes 100 test files in about 6 seconds but only takes into account the first page of the TIF.
I then grabbed a second code from the web to have all pages processed and this is it:
vb.net Code:
Sub SurroundingSub(FullName As String, Name As String)
Dim document As iTextSharp.text.Document = New iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 0, 0, 0, 0)
Dim writer As iTextSharp.text.pdf.PdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(document, New System.IO.FileStream(Application.StartupPath & "" & Name & ".pdf", System.IO.FileMode.Create))
Dim bm As System.Drawing.Bitmap = New System.Drawing.Bitmap(FullName)
Dim total As Integer = bm.GetFrameCount(System.Drawing.Imaging.FrameDimension.Page)
document.Open()
Dim cb As iTextSharp.text.pdf.PdfContentByte = writer.DirectContent
For k As Integer = 0 To total - 1
bm.SelectActiveFrame(System.Drawing.Imaging.FrameDimension.Page, k)
Dim img As iTextSharp.text.Image = iTextSharp.text.Image.GetInstance(bm, ImageFormat.Tiff)
img.SetAbsolutePosition(0, 0)
img.ScaleAbsoluteHeight(document.PageSize.Height)
img.ScaleAbsoluteWidth(document.PageSize.Width)
cb.AddImage(img)
document.NewPage()
Next
document.Close()
End Sub
This converts the 100 files from before, putting both pages into the PDF, in about 80 seconds.
Is this much difference normal? I mean, I would have expected double the time, maybe a little more, but not more than 13 times as much...
I'd like to understand if I'm doing something wrong or if it's normal...
Obviously the two pages of each TIF are almost identical, if you need I'll share them.
Thank you to those who will take the time to answer me.
-
Jul 25th, 2021, 02:12 AM
#2
Re: ITextSharp - Different performance between file reading and TIFF page reading
You should use the Stopwatch class to time various aspects of your code to see if you can identify where the difference is. For instance, use the principles of the second code but for only one page and see how long that takes. This is the difference between software development and writing code.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|