PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Token '38438' not expected
https://forum.pdfsharp.net/viewtopic.php?f=3&t=883
Page 1 of 1

Author:  mmisol [ Wed Sep 23, 2009 3:43 pm ]
Post subject:  Token '38438' not expected

Hi, I have been using PDFSharp for a while and it has been working OK, but recently users have found problems with PDF files generated with a new scanner.
When the following line of code is executed:

Code:
PdfDocument inputDocument = PdfReader.Open(file, PdfDocumentOpenMode.Import)


an exception of type PdfReaderException is raised with the following message: Token '38438' was not expected.

Could this be that the PDF file generated by the scanner contains elements not supported by PDFSharp? Is there an easy way to fix this problem modifying the code? The problem file can be downloaded from http://theglobe.urudata.com/jbriosso/FACTURA-DISTRICOMP.pdf.

Thanks in advance!

Regards,
Martin

Author:  Thomas Hoevel [ Wed Sep 23, 2009 4:10 pm ]
Post subject:  Re: Token '38438' not expected

Hi, Martin,

this is not my area of expertise, but I have a patch that'll work with that file (I hope you don't come up with cruder files ...).

In Parser.cs you'll find
Code:
internal PdfTrailer ReadTrailer()


Replace this old code
Code:
string trail = this.lexer.ReadRawString(length - 31, 30); //lexer.Pdf.Substring(length - 30);
int idx = trail.IndexOf("startxref");
this.lexer.Position = length - 31 + idx;


with this new snippet:
Code:
string trail = this.lexer.ReadRawString(length - 131, 130);
int idx = trail.IndexOf("startxref");
this.lexer.Position = length - 131 + idx;

Author:  mmisol [ Wed Sep 23, 2009 4:20 pm ]
Post subject:  Re: Token '38438' not expected

Thanks Thomas, I will try what you suggest.

Author:  mmisol [ Wed Sep 23, 2009 5:24 pm ]
Post subject:  Re: Token '38438' not expected

It worked great! Thanks!

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