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

Error in Parser.ReadTrailer()
https://forum.pdfsharp.net/viewtopic.php?f=3&t=273
Page 1 of 1

Author:  wmausz [ Mon Dec 10, 2007 12:05 pm ]
Post subject:  Error in Parser.ReadTrailer()

Hello!

In one of my projects I have to merge PDF files (produced by SAP) into one big PDF. I tried your library and found a bug in either the library or (also possible) the PDFs I have to merge.

In the function ReadTrailer() you are reading the last 30 bytes and then you search for the startxref symbol. My PDFs I got for testing have a lot of \0 bytes at the end (more than 30! ) which will make it impossible for your ReadTrailer-function to find the requested symbol. I corrected the function to be able to read my PDFs from SAP in the following way:

internal PdfTrailer ReadTrailer()
{
//Symbol symbol;
//string token;
//int xrefOffset = 0;
int length = lexer.PdfLength;

// YOUR ORIGINAL CODE --> COMMENTED OUT
//string trail = this.lexer.ReadRawString(length - 31, 30); //lexer.Pdf.Substring(length - 30);
//int idx = trail.IndexOf("startxref");

// SCANNING THE WHOLE DOCUMENT FOR THE LAST startxref -> will also work if bytes are added at the end
string trail = this.lexer.ReadRawString(0, length);
int idx = trail.LastIndexOf("startxref");

//this.lexer.Position = length - 31 + idx;
this.lexer.Position = idx;

ReadSymbol(Symbol.StartXRef);
this.lexer.Position = ReadInteger();
...

I just wanted to give a feedback to this problem, maybe it is useful for you and you can consider it for future versions.

Bye,

Wilfried Mausz

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