Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GetPage fails with error : 'Cannot convert array to rectangle' #29

Closed
jdenieul opened this issue Jan 20, 2019 · 10 comments
Closed

GetPage fails with error : 'Cannot convert array to rectangle' #29

jdenieul opened this issue Jan 20, 2019 · 10 comments

Comments

@jdenieul
Copy link

jdenieul commented Jan 20, 2019

Hello,

When i try to open a PDF file and read it, i have an error :

UglyToad.PdfPig.Exceptions.PdfDocumentFormatException : 'Cannot convert array to rectangle, expected 4 values instead got: [ 0, 0 ].'

UglyToad.PdfPig.Exceptions.PdfDocumentFormatException
HResult=0x80131500
Message=Cannot convert array to rectangle, expected 4 values instead got: [ 0, 0 ].
Source=UglyToad.PdfPig
Arborescence des appels de procédure :
à UglyToad.PdfPig.Util.ArrayTokenExtensions.ToIntRectangle(ArrayToken array)
à UglyToad.PdfPig.Parser.PageFactory.GetMediaBox(Int32 number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers, Boolean isLenientParsing)
à UglyToad.PdfPig.Parser.PageFactory.Create(Int32 number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers, Boolean isLenientParsing)
à UglyToad.PdfPig.Content.Pages.GetPage(Int32 pageNumber)
à UglyToad.PdfPig.PdfDocument.GetPage(Int32 pageNumber)
à WindowsFormsApp2.Form1.button1_Click(Object sender, EventArgs e) dans C:\Users\source\repos\WindowsFormsApp2\WindowsFormsApp2\Form1.cs :ligne 40
à System.Windows.Forms.Control.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
à System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
à System.Windows.Forms.Control.WndProc(Message& m)
à System.Windows.Forms.ButtonBase.WndProc(Message& m)
à System.Windows.Forms.Button.WndProc(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
à System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
à System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
à System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
à System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
à System.Windows.Forms.Application.Run(Form mainForm)
à WindowsFormsApp2.Program.Main() dans C:\Users\source\repos\WindowsFormsApp2\WindowsFormsApp2\Program.cs :ligne 19

Hope it will help you to fix it,

@EliotJones
Copy link
Member

EliotJones commented Jan 21, 2019

Thanks, I will try to take a look into this tonight, I was fairly sure the MediaBox for a page should have 4 numbers but I'll check the spec and the PDFBox code and see what they're doing. Would you be able to send me the document so I can check the parsing logic or is it confidential?

@EliotJones
Copy link
Member

I've attached a version which works around this problem however I think the problem is deeper in the code which parses the PDF objects.

If you can send me the document or alternatively open the document in a text editor such as notepad++ or Visual Studio and find the part of it which will look something like (using the /MediaBox text):

<< /Contents 57 0 R /MediaBox [ 0 0 612 792 ] /Parent 72 0 R /Resources 65 0 R /Type /Page >>

And send that part to me it would be a huge help to make sure the library works for other cases, thanks, Eliot.
PdfPig.0.0.5.1.zip

@jdenieul
Copy link
Author

I can send you this :

<< /Type /Page /Parent 4 0 R /MediaBox [ 0 0 595.28 841.89 ] /Resources <<

It ok for you or you need more ?

@EliotJones
Copy link
Member

EliotJones commented Jan 21, 2019

Thank you, I've run that through the parser and it seems to come through ok, are there other instances of the /MediaBox token in this document (generally there will be 1 per page in the document)?

If you can't share it publicly you could email it to me at elioty(at)hotmail.co.uk

@jdenieul
Copy link
Author

No problem, i have one /MediaBox per page.

@EliotJones
Copy link
Member

Did the last release fix the problem for you or is it still present?

@jdenieul
Copy link
Author

jdenieul commented Jan 24, 2019 via email

@jdenieul
Copy link
Author

Hi,

I have now a new problem :

Une exception a été levée par l'initialiseur de type pour 'UglyToad.PdfPig.Fonts.SystemFonts.SystemFontFinder'.

à UglyToad.PdfPig.Fonts.SystemFonts.SystemFontFinder..ctor(TrueTypeFontParser trueTypeFontParser)
à UglyToad.PdfPig.Parser.PdfDocumentFactory.OpenDocument(IInputBytes inputBytes, ISeekableTokenScanner scanner, IContainer container, Boolean isLenientParsing) dans C:\git\UglyToad.PdfPig\src\UglyToad.PdfPig\Parser\PdfDocumentFactory.cs:ligne 110
à UglyToad.PdfPig.Parser.PdfDocumentFactory.Open(IInputBytes inputBytes, ParsingOptions options) dans C:\git\UglyToad.PdfPig\src\UglyToad.PdfPig\Parser\PdfDocumentFactory.cs:ligne 63
à UglyToad.PdfPig.Parser.PdfDocumentFactory.Open(String filename, ParsingOptions options) dans C:\git\UglyToad.PdfPig\src\UglyToad.PdfPig\Parser\PdfDocumentFactory.cs:ligne 40
à UglyToad.PdfPig.PdfDocument.Open(String filePath, ParsingOptions options) dans C:\git\UglyToad.PdfPig\src\UglyToad.PdfPig\PdfDocument.cs:ligne 99
à WindowsFormsApplication1.Form1.button1_Click(Object sender, EventArgs e) dans Y:\Developpement\WindowsFormsApplication1\WindowsFormsApplication1\Form1.cs:ligne 24
à System.Windows.Forms.Control.OnClick(EventArgs e)
à System.Windows.Forms.Button.OnClick(EventArgs e)

@EliotJones
Copy link
Member

Sorry for the delay on getting back to you. There's just not enough information in this error message to guess at a fix to be honest. It looks like the InnerException might contain a more valuable exception.

PdfPig.0.0.5.2.zip

I've attached an updated package with a change that wraps the static initializer (which I think is throwing) in a try-catch but it's not going to fix whatever the problem is here...

@EliotJones
Copy link
Member

Sorry I wasn't able to be more help here but without the original document it's very difficult to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants