PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.com/

Error Opening a Document After Save
http://forum.pdfsharp.com/viewtopic.php?f=2&t=3892
Page 1 of 1

Author:  jr_repree [ Fri Dec 07, 2018 7:02 pm ]
Post subject:  Error Opening a Document After Save

I'm running into an odd problem. With certain documents, following saving them with PdfSharp, when I try to open them in Adobe Reader, I get the following error message: "There was an error processing a page. A number is out of range."

The simplest version of the code that reproduces this error is as follows:
Code:
using (var pdfDoc = PdfSharp.Pdf.IO.PdfReader.Open(sourcePath, PdfDocumentOpenMode.Modify))
{
  pdfDoc.Save(destPath);
}


The above code runs without any exceptions being thrown so I have no idea that anything went wrong until I actually try to open the new file.

Unfortunately I can't share the documents since they have personal information on them, but the commonality seems to be that they were previously signed using DocuSign. I've tried to create a file that causes the error, but I've been unable to do so.

I know that without access to the original documents, it's unlikely that anyone could definitively say what's happening, but does anyone have any advice as to how I could troubleshoot this issue?

Author:  jr_repree [ Fri Dec 21, 2018 8:21 pm ]
Post subject:  Re: Error Opening a Document After Save

I've narrowed down the issue by inspecting the difference between the underlying raw data in the file before and after the save. It appears that the issue relates somehow to this block of code in PDFSharp:

https://github.com/empira/PDFsharp/blob ... ge.cs#L613

Basically, the following gets inserted into the page on save:

Code:
/Group
<<
/CS/DeviceRGB
/S/Transparency
>>


This appears to somehow be conflicting with other content in the page because if I manually remove that entry, I can at least open and see the contents of the page (though I do get the following error message upon attempting to open it with Adobe Reader "An error exists on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem.")

I've been reading through the PDF spec to try to figure out what's wrong, but I haven't been able to find anything useful.

Does anyone have any ideas on what might be going on or how I might be able to troubleshoot this issue?

Author:  TH-Soft [ Sat Dec 22, 2018 8:42 am ]
Post subject:  Re: Error Opening a Document After Save

Judging from the PDFsharp code, that group should not be added when you set
Code:
PdfDocument.Options.ColorMode = PdfColorMode.Undefined

Author:  jr_repree [ Wed Jan 09, 2019 2:53 pm ]
Post subject:  Re: Error Opening a Document After Save

Thanks for the suggestion.

I tried setting the PdfColorMode to Undefined and I confirmed that the setting was properly applied in the new document, but I continued to run into the same error, so looks like I was incorrect in the root cause.

Back to the drawing board, I guess.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/