views:

430

answers:

2

am using iTextSharp ( .NET 2.0 Vista ). The iTextSharp Version is 4.1.2.0

PdfReader reader = new PdfReader(pdfFile); 

is causing the library to thrown an exception saying "Trailer not found"
The file exists and can be viewed in Adobe no problem Any ideas?

+1  A: 

The trailer is a part the structure of a PDF file. If you're getting an error saying it can't be found then the first thing I'd think is your file is corrupt. Being able to open the PDF in a PDF viewer program doesn't necessarily mean the PDF isn't corrupt; I understand that if it's a linearized PDF file the viewer won't attempt to use the trailer.

Does your code throw an IOException for any PDF you attempt to read?

  • If so, then maybe using a more recent version of iTextSharp will help or at least post some code.
  • If not, then I'd work on recreating the PDFs you're trying to process.
Jay Riggs
we dont control the PDF or rather where it comes in from . typically we process PDF that come in as attachments on an email so ...the code works fine for about 95% of the PDF's we have tested on and also I have tried this with the latest librariesSo what did you mean by re-create?Thanks
Rahul
I was hoping you did control the creation of your PDFs and could do so and prevent the error. I suppose the only thing I can suggest is to repair the PDFs you get the error on. If you Google 'PDF repair' a number of hits are returned but since I've never had to do this I can't make any specific recommendations. Sorry.
Jay Riggs
After doing some testing, I found that the issue I had related to a corrupt PDF. As soon as I ran an pdf repair, the file worked correctly. Thanks.
Jon
A: 

Can anyone suggest how to handle this type of files in code or what is the solution because we can view files but can not process through iTextSharp. We are merging different pdf files and if any of these file comes then it doesn't work. We can not ignore any file. please reply.

MergePDF