Anshit Hayaran

Anshit Hayaran

  • NA
  • 19
  • 5.5k

Split PDF FIle for corrupt PDF

May 12 2020 7:41 AM
I am trying to split a 'n' paged pdf file to 'n' number of pdf files containing 1 page each in ".net". For normal pdf files, PDFSharp is working fine but for corrupt file its showing errors listed down. When I use Adobe Reader and 'Save As' the file, the new file is uncorrupted one. But I do not want to do it manually. I tried to open the pdf in Adobe reader using 'Process' but I can't save from there without manually saving it. If I use other DLLs the job gets done but it adds watermark.
Errors while opening the PDF Doc:
• "Invalid entry in XRef table, ID=9, Generation=0, Position=0, ID of referenced object=1, Generation of referenced object=0"
• {"Unexpected character '0xffff' in PDF stream. The file may be corrupted. If you think this is a bug in PDFsharp, please send us your PDF file."}
• Object already in use exception.
For handling corrupt files through process I tried this:
Process p = new Process();
p.StartInfo.FileName = file;
p.Start();
p.Close();
corrupt = true;
inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import);
Please help me ASAP... Thanks in advance.

Answers (4)