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
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:
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. :)
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. :)