Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
PDF file crashes QuickPDF |
Post Reply |
Author | |
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
Posted: 20 Oct 16 at 8:45AM |
Hi Ross,
QuickPDF wasn't written in C++ - it's 100% pure object pascal code (Delphi). There are only less external calls inside and these calls are for external render engines like gdiplus, pdfium and cairo. It depends on your used functionalities if an external call to a render engine will be activated. gdiplus can be a problem 'cause not all windows versions still have it in the standard installation. QuickPDF offers functionality to manage the calls/task to these render engines - please check the QuickPDF online reference. To free memory there's not only a FreeDocument - you can free instances and many more (check the online reference). If your code works with 99% other pdf-files and fails only with less pdfs you should debug/deal with similar pdfs. Is your code working with the file i've mentioned (you can try google to get it)? You should deal with the dpi-value. What's in "dc" after "g.GetHdc()"? What's in "renderDpi"? You can reduce/remove code to check if the file is loaded in a proper way first. You can check the returning value of each function if the function/step is okay. Regarding your suggestions (skype, debug session, ...): This is only a user-community here. I like to give quick hints, post a code snippet out of my personal codings, post a link to a kb-ressource, ... But not more - it's my free time i'm spending here ;-) |
|
Cheers,
Ingo |
|
RossFaneuf
Beginner Joined: 07 Oct 16 Location: Woburn MA USA Status: Offline Points: 5 |
Post Options
Thanks(0)
|
Please read the first post in this thread, where the c# code in question is provided.
The crash occurs the second time the following line of code is executed for this pdf file: quickPDFLibrary.RenderPageToDC(renderDpi, 1, dc) I realize that including all the code in the try..catch is providing too much information, for which I apologize. Note that near the end of the code the following line attempts to free everything associated with the open document. Should there be additional calls first to remove something else created by the RenderPageToDC() method before calling this? quickPDFLibrary.RemoveDocument(docID); I am certain that:
- there are no string handling issues - we are using the correct library - in fact, I have tested the code against this pdf file with 2 versions, 11.14 and 13.11 - This code has worked correctly for 1000s of pdf files, including some strange ones. - I assume the fact that the crash is in unmanaged code is because some of the QuickPDF internals are implemented using unmanaged code (C++?) If you would prefer to discuss this using Skype, send an invitation to ross.faneuf. I can, if you wish, share screens for a debugging session. |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Ross,
only a quick short answer... The problem will be in your code. I've downloaded a simmilar pdf (The Hydraulic Geometry of Stream Channels and Some Physiographic Implications.pdf) from the same authors. 64 scanned pages and text, too. It works fine with my app made by QuickPDF. If you're writing about "unmanaged code" i think wrong string handling could be your problem? Which is your dev-language... C#? Perhaps you're using the wrong dll-version for your language? You should read the descriptions on the debenu-page which dll shall be used by which language... |
|
Cheers,
Ingo |
|
RossFaneuf
Beginner Joined: 07 Oct 16 Location: Woburn MA USA Status: Offline Points: 5 |
Post Options
Thanks(0)
|
The file is readable, not encrypted, and has no password. It appears to 64 pages of scanned images of a technical paper published in 1953. The file is readable with Adobe Reader.
Internally, the file can be successfully read once with the supplied code, but a crash occurs on the second attempt, and the crash is in unmanaged code. The file is available in DropBox at: file:///C:/Users/ross.INMAGICINC/Dropbox/Leopold_and_Maddock_1953_Hydraulic_Geometry.pdf |
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi Ross,
on which codeline you've determined the crash? You can't attach the file here. You should upload it anywhere with a free filehoster. What about the security settings of this pdf... is there a user password... is the file write protected...? If the pdf is already encrypted you should decrypt it first. Cheers and welcome here, Ingo |
|
Cheers,
Ingo |
|
RossFaneuf
Beginner Joined: 07 Oct 16 Location: Woburn MA USA Status: Offline Points: 5 |
Post Options
Thanks(0)
|
Need help attaching the .pdf file to this topic. How is this done???
|
|
RossFaneuf
Beginner Joined: 07 Oct 16 Location: Woburn MA USA Status: Offline Points: 5 |
Post Options
Thanks(0)
|
The attached .pdf file crashes the following c# method. Using QuickPDF 13.11. The method attempts to construct a thumbnail image based on the first page in the .pdf file. The sequence is:
- Method succeeds once - When called a second time with the same .pdf file QuickPDF dies in unmanaged code. The code which attempts to create the image: try { PDFLibrary quickPDFLibrary = PDFTextExtractor.GetQuickPdfLibrary(); if (quickPDFLibrary.LoadFromString(pdfBytes, "") == 1) // Success { int docID = quickPDFLibrary.SelectedDocument(); // NEEDED per Debenu expert //Declare as a double so that precision is not lost when determining the DPI based on the destination size. //If the pdf is large enough (PageWidth or PageHeight having a value greater than 7200) the result can have a value of 0. //If this occurs then thumbnail will not be created. double renderDpi = 72; // SPR 9989: Advance to first page, and compute resolution which will roughly match rendered bitmap to desired size. quickPDFLibrary.SelectPage(1); double pw = quickPDFLibrary.PageWidth() / renderDpi; double ph = quickPDFLibrary.PageHeight() / renderDpi; //Setup the render DPI based on the destination size renderDpi = Math.Min(destSize / pw, destSize / ph); // fit both int width = (int)(renderDpi * pw); int height = (int)(renderDpi * ph); Bitmap bitmap = new Bitmap(width, height); using (Graphics g = Graphics.FromImage(bitmap)) { // Render page into the bitmap IntPtr dc = g.GetHdc(); quickPDFLibrary.RenderPageToDC(renderDpi, 1, dc); g.ReleaseHdc(dc); // Draw 1-pixel black border onto the bitmap Pen bp = new Pen(Brushes.Silver, 1); g.DrawLine(bp, 0, 0, width - 1, 0); g.DrawLine(bp, width - 1, 0, width - 1, height - 1); g.DrawLine(bp, width - 1, height - 1, 0, height - 1); g.DrawLine(bp, 0, height - 1, 0, 0); } using (MemoryStream outStream2 = new MemoryStream()) { //height greater then width double thmbHeight; double thmbWidth; //Get the dimension of the thumbnail GetResizeImageDimensions(bitmap, destSize, out thmbHeight, out thmbWidth); // Generate thumbnail image Image thumbNailImg = bitmap.GetThumbnailImage(Convert.ToInt32(thmbWidth), Convert.ToInt32(thmbHeight), ThumbnailCallback, IntPtr.Zero); thumbNailImg.Save(outStream2, ImageFormat.Png); thumbNailImg.Dispose(); // Remove document from memory quickPDFLibrary.RemoveDocument(docID); return outStream2.ToArray(); } } } |
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store