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
|