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

Unexpected token in PDF file
https://forum.pdfsharp.net/viewtopic.php?f=2&t=628
Page 1 of 1

Author:  cg_sireesh [ Wed Feb 04, 2009 5:04 am ]
Post subject:  Unexpected token in PDF file

Hi,

When I open PDF file with Modify mode am getting error message. i.e Unexpected token in PDF file. The PDF file may be currupt. If it is not, please send us the file for serivce.

Code:
Code:
PdfSharp.Pdf.IO.PdfReader.Open(filePath, PdfSharp.Pdf.IO.PdfDocumentOpenMode.Modify);


Please give the solutions.

Author:  Thomas Hoevel [ Wed Feb 04, 2009 10:39 am ]
Post subject: 

Hi!

We need the PDF file to investigate the issue.

Author:  Thomas Hoevel [ Wed Feb 04, 2009 4:16 pm ]
Post subject: 

Hi!

The file is not corrupted, but contains an unusual name/value pair.

Here's a fix for that: in PdfRectangle.cs (2 new lines):
Code:
internal PdfRectangle(PdfItem item)
{
  if (item == null)
    return;

  // 2 new lines below:
  if (item is PdfNull)
    return;
  // 2 new lines above

  if (item is PdfReference)
    item = ((PdfReference)item).Value;

  PdfArray array = item as PdfArray;
  if (array == null)
    throw new InvalidOperationException(PSSR.UnexpectedTokenInPdfFile);

  this.x1 = array.Elements.GetReal(0);
  this.y1 = array.Elements.GetReal(1);
  this.x2 = array.Elements.GetReal(2);
  this.y2 = array.Elements.GetReal(3);
}


This is not the solution for all "unexpected token" errors, but at least for one.

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