I’m by no means a good programmer (and know zilch about C#) and I read this
list to learn more about PDF and iText issues/usages but it seems to my humble
mind (not fishing for compliments here BTW) that you open many files within the
while loop (pdfDoc.Open()) but close them only once outside the loop. So to the
unsuspecting it look as if you close only the last file opened.
What I would try is moving the close inside the loop and keep my fingers
crossed. But I have been wrong (too many times …)
/Gerold
Von: todd.patter...@gm.com [mailto:todd.patter...@gm.com]
Gesendet: Montag, 22. April 2013 13:00
An: itext-questions@lists.sourceforge.net
Betreff: [iText-questions] Merge PDF File release
Thank You for the quick response.
I have changed the code to the following
I am now using pdfCopy.
I still have the same error stating I can not delete the original pdf files
because they are in use.
Any help would be greatly appreciated.
Thanks,
Todd
Private Sub BuildMultiPagePDF(ByVal fileArray As String(), ByVal outPutPDF As
String)
Try
Dim reader As iTextSharp.text.pdf.PdfReader = Nothing
Dim pageCount As Integer = 0
Dim currentPage As Integer = 0
Dim pdfDoc As iTextSharp.text.Document = Nothing
Dim writer As iTextSharp.text.pdf.PdfCopy = Nothing
Dim page As iTextSharp.text.pdf.PdfImportedPage = Nothing
Dim currentPDF As Integer = 0
If fileArray.Length > 0 Then
reader = New
iTextSharp.text.pdf.PdfReader(fileArray(currentPDF))
reader.ResetReleasePage()
pdfDoc = New
iTextSharp.text.Document(reader.GetPageSizeWithRotation(1))
writer = New iTextSharp.text.pdf.PdfCopy(pdfDoc, _
New
System.IO.FileStream(outPutPDF, _
System.IO.FileMode.OpenOrCreate, _
System.IO.FileAccess.Write))
pageCount = reader.NumberOfPages
While currentPDF < fileArray.Length
pdfDoc.Open()
While currentPage < pageCount
currentPage += 1
pdfDoc.SetPageSize(reader.GetPageSizeWithRotation(currentPage))
pdfDoc.NewPage()
page = writer.GetImportedPage(reader, currentPage)
writer.AddPage(page)
End While
currentPDF += 1
If currentPDF < fileArray.Length Then
reader = New
iTextSharp.text.pdf.PdfReader(fileArray(currentPDF))
pageCount = reader.NumberOfPages
currentPage = 0
End If
End While
pdfDoc.Close()
Else
MessageBox.Show("The input file array is empty. Processing
terminated.", _
"INVALID FILE LIST", _
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
Catch ex As Exception
MessageBox.Show(ex.message)
End Try
End Sub
-----mkl <m...@wir-sind-cool.org<mailto:m...@wir-sind-cool.org>> wrote: -----
To:
itext-questions@lists.sourceforge.net<mailto:itext-questions@lists.sourceforge.net>
From: mkl <m...@wir-sind-cool.org<mailto:m...@wir-sind-cool.org>>
Date: 04/20/2013 09:05AM
Subject: [iText-questions] [SPAM] Re: Merge PDF File release
todd.patterson,
todd.patterson wrote
> I use the close command for the document
Yes, you close the document but I don't see you closing any of the
PdfReaders or the PdfWriter, neither explicitely nor implicitely (e.g. by
utilizing a using statement). iText in the latest 10...15 releases more and
more stopped to do close calls itself as that disturbs some use cases, e.g.
when pages from a single document are imported in multiple other documents.
Furthermore your code is essentially merging source PDFs as is into a single
destination PDF. Using PdfWriter is not the optimal way to implement that;
if you used some Pdf*Copy* variant instead, you wouldn't have to deal with
all this page size and page orientation stuff, interactive features would be
copied, too, as good as possible, and the resulting PDF would internally be
better organized (not immediate a problem, but trouble might ensue if that
process is repeated multiple times).
You might want to read the (freely available) chapter 6 of iText in Action,
2nd edition, especially the later sections.
Regards, Michael
--
View this message in context:
http://itext-general.2136553.n4.nabble.com/Merge-PDF-File-release-tp4658071p4658073.html
Sent from the iText - General mailing list archive at Nabble.com.
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net<mailto:iText-questions@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php
Nothing in this message is intended to constitute an electronic signature
unless a specific statement to the contrary is included in this message.
Confidentiality Note: This message is intended only for the person or entity to
which it is addressed. It may contain confidential and/or privileged material.
Any review, transmission, dissemination or other use, or taking of any action
in reliance upon this message by persons or entities other than the intended
recipient is prohibited and may be unlawful. If you received this message in
error, please contact the sender and delete it from your computer.
------------------------------------------------------------------------------
Precog is a next-generation analytics platform capable of advanced
analytics on semi-structured data. The platform includes APIs for building
apps and a phenomenal toolset for data science. Developers can use
our toolset for easy data analysis & visualization. Get a free account!
http://www2.precog.com/precogplatform/slashdotnewsletter
_______________________________________________
iText-questions mailing list
iText-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/itext-questions
iText(R) is a registered trademark of 1T3XT BVBA.
Many questions posted to this list can (and will) be answered with a reference
to the iText book: http://www.itextpdf.com/book/
Please check the keywords list before you ask for examples:
http://itextpdf.com/themes/keywords.php