![]() ![]() It only merges PDF files right now, but I'm planning on adding methods for additional functionality later. It's probably overkill, but I put together some code that merges multiple PDFs into a single file that I posted on the Code Review SE site (the post, VB.NET - Error Handling in Generic Class for PDF Merge, contains the full class code). I realize I'm pretty late to the party, but after reading the comments from I wanted to see if I could put something together myself that uses the examples from his linked sample chapter. 'When all done, we close the document so that the pdfwriter object can write it to the output file 'Increment f and read the next input pdf file 'Then add the imported page to the PdfContentByte object as a template based on the page's rotationĬb.AddTemplate(page, 0, -1.0F, 1.0F, 0, 0, reader.GetPageSizeWithRotation(i).Height)Ĭb.AddTemplate(page, 0, 1.0F, -1.0F, 0, reader.GetPageSizeWithRotation(i).Width + 60, -30)Ĭb.AddTemplate(page, 1.0F, 0, 0, 1.0F, 0, 0) 'If it is the 1st page, we add bookmarks to the page ![]() 'Create a new page on the output document PdfDoc.SetPageSize(reader.GetPageSizeWithRotation(i)) 'Loop thru the current input pdf's pages starting at page 1 Writer = PdfWriter.GetInstance(pdfDoc, New FileStream(outputPath, FileMode.OpenOrCreate)) PdfDoc = New (reader.GetPageSizeWithRotation(1), 18, 18, 18, 18) Public Shared Function MergePdfFiles(ByVal pdfFiles() As String, ByVal outputPath As String) As Booleanĭim pdfCount As Integer = 0 'total input pdf file countĭim f As Integer = 0 'pointer to current input pdf fileĭim reader As = Nothingĭim pdfDoc As = Nothing 'the output pdf document I pass an array of file paths as strings and the output file i would like. I have a console that monitors individual folders in a designated folder then needs to merge all of the pdf's in that folder into a single pdf. I did some debugging and have tracked the problem down to the following lines: copy.AddPage(copy.GetImportedPage(reader,Ĭopy.AddPage(copy.GetImportedPage(reader, page))) Private Function MergeFiles(ByVal sourceFiles As List(Of Byte())) As Byte()įor i As Integer = 0 To sourceFiles.Count - 1ĭim reader As New PdfReader(sourceFiles(i))Ĭopy.AddPage(copy.GetImportedPage(reader, page))Īn item with the same key has already been added. The actual code is in C# and I converted that to VB.NET. I am using the iText.sharp library, and collect converted the code and tried to use it (from here) I have to merge multiple PDFs into a single PDF. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |