3
votes

I receive unhandled exception for specific pdf files using iTextSharp libraries in .net (c#) project. I cannot understand what is specific with pdf I want to upload, though I can see that with basic pdf I download from internet functionality works. The following part of code:

string pdfTemplate ="url to specific pdf"; var pdfReader = new PdfReader(pdfTemplate);

throw exception: Rebuild failed: Dictionary key Z is not a name. at file pointer 224; Original message: Dictionary key Z is not a name. at file pointer 224

Please, any suggestions? I'm out of ideas...

1

1 Answers

9
votes

There is an error in the document info dictionary:

%PDF-1.4
1 0 obj
<<
/Title (þÿ)
/Creator (þÿ)
/Producer (þÿ Q t   4 . 8 . 2   \( C \)   2 0 1 1   N o k i a   C o r p o r a t i o n   a n d / o r   i t s   s u b s i d i a r y \( - i e s \))
/CreationDate (D:20131111142910)Z)
>>
endobj 

There are two closing brackets for the CreationDate value. iText correctly assumes the first one to be correct, i.e. finishing the value, and, therefore, considers the Z to be the key of the next entry.

But a key has to be a name, and a name starts with a slash, but this name-to-be has no slash. Syntax-Error!! Thus:

Dictionary key Z is not a name. at file pointer 224

The PdfReader as a last resort after a failure tries to read the PDF again, this time first trying to reconstruct the cross references. As the Problem is not related to the cross references at all, this obviously fails again. Thus:

Rebuild failed: Dictionary key Z is not a name. at file pointer 224; Original message: Dictionary key Z is not a name. at file pointer 224

The creation of this syntax error might be a Qt bug (Qt 4.8.2 being named as the creator here).

PS: Have you tried opening the document properties of this file in Adobe Reader? Nothing pops up here which surely is due to that issue.