I'm trying to merge a whole bunch of pdfs together. This is what I have so far
using (FileStream stream = new FileStream(OutputDirectory+"/"+ OutputFileName+".pdf", FileMode.Create))
{
Document pdfDoc = new Document();
PdfCopy pdf = new PdfCopy(pdfDoc, stream);
pdfDoc.Open();
Console.WriteLine("Merging files count: " + Input.Count);
int i = 1;
foreach (var item in Input)
{
Console.WriteLine(i + ". Adding: " + item.FileName);
pdf.AddDocument(new PdfReader(item.FileWithPath));
i++;
}
pdfDoc.Close();
Console.WriteLine("PDF merge complete.");
}
However, after some pdfs have been merged properly, I get this exception:
iTextSharp.text.exceptions.InvalidPdfException: 'Rebuild failed: trailer not found.; Original message: PDF startxref not found.'
Its pointing at my pdf.AddDocument(new PdfReader line
I have looked around and some comments have mentioned that my file is corrupt. However, I am able to open and read the source pdfs without any issue. I am unsure of how to continue now.