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!

Debenu Quick PDF Library - PDF SDK Community Forum Homepage
Forum Home Forum Home > For Users of the Library > I need help - I can help
  New Posts New Posts RSS Feed - LoadFromFile - Error 401
  FAQ FAQ  Forum Search   Register Register  Login Login

LoadFromFile - Error 401

 Post Reply Post Reply
Author
Message
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Topic: LoadFromFile - Error 401
    Posted: 22 Apr 19 at 10:03PM
I am currently running Delphi 7 and using QuickPDF 8.16.
One of the issues I have recently started getting is randomly the LoadFromFile() method returns 0 then when I check LastErrorCode it is 401 = "Could not open file".

This seems to be so random and I have been trying for over a month to consistently reproduce the problem with no luck. What I do know if that when my application gets the 401 error I can halt my application by showing the error dialog. And while the error is showing I can use windows file explorer and open and close the file with adobe reader, I can delete the file and copy the file back. I can do pretty much anything I want. I can run a different program and it will open the file with no problem. In fact, if I simply close my app and reopen it, it can open that same pdf without any error as well. Eventually it will get this error again but is impossible to follow certain steps (that I know of) to reproduce it.

Like I said I have tried for over a month to figure out what is causing this. Is there any other details I can get from Quick PDF as to why it is failing to open the PDF?

Any help would be greatly appreciated.


Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 22 Apr 19 at 10:28PM
If you can get the error to happen fairly reliably, the tool I would use to find the cause is Process Monltor from Sysinternals.  However if you have not used this before, be warned that there is a learning curve!  Procmon can trace all file-system calls in all processes, and it can be filtered to show only those relating to the pathname of your file (otherwise there is a huge amount of output, of course).  It will tell you precisely why the file open failed, if it failed on a file open operation.  Have you ruled out the possibility of anti-virus opening and locking the file to check it?  This can cause random open failures, but PDF files are not always of interest to an AV.
Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 22 Apr 19 at 10:33PM
I have now read your other post; if file is being opened successfully but contains a PDF feature that causes QPDF to "fail", this would not of course show up when Procmon monitors OS calls.  But it would also not happen randomly for the same file.
Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 22 Apr 19 at 10:51PM
401 means "could not open input file"...
I know that's your version is an old one but the code should be matching:
https://www.debenu.com/docs/pdf_library_reference/LastErrorCode.php

Cheers,
Ingo

Back to Top
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Posted: 22 Apr 19 at 10:54PM
I've considered the AV issue, but it happens on different computers, some without AV, on different networks it will even happen when running on a terminal server. I have personally never been able to get this application to fail but I have one customer which it happens every day for and now I have a customer support employee which it occurred once for and for several days that person has tried to make it happen again and has yet to make it happen again. I used Process Monitor like twice many years ago so I would have to learn from scratch and then I have no idea when or which computer it will show its ugly head again on.

Having said all of this, this application has been in use heavily for about 20 years. PDFs being a part of that for over 10 years and it just recently started happening. The only thing I can think of that might line up with when this started happening (a few months ago) is we started using FoxIt PhantomPDF editor to modify some PDFs. But the fact it will work one time and not the next makes it really hard to associate that. Unless it is simply corrupting memory somehow.


Thanks for suggestions though, every tip is helpful.

Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 23 Apr 19 at 9:52AM
For network files you will see a 401 while any other user has the file open in Adobe Reader or Acrobat.

If this is not the problem, then one more suggestion: do you retry this failure?  Just run the open in a loop, with a Sleep() for say 100ms and only show the error to the user when 10 attempts have failed (vary timings as you think fit).  Since you talk of a network it is possible that the file may be visible but not available, if it has been recently written. This can be made much worse if any of the computers are on mixed networks with some XP/2003 still involved.  
Back to Top
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Posted: 23 Apr 19 at 7:02PM
Thanks for the suggestions, but I don't think any of that applies. The files are on a local folder on the local hard drive with only program that touches the files. Yes I did put retry logic. What is crazy is you can start the app and it will open the files just fine. It may open them fine all day long as the user performs various functions. Then what appears to be totally random is a file it has opened fine all day, all of a sudden it will fail to open. We can retry over and over and once it fails the first time, then it will fail every single time. The only way to get it to work again is to close the application and start it again. Also while the application is modal (while I am showing an error) you can open the file via file explorer using a varity of other apps like Adobe Reader. then the error message dialog has a retry button so after you have proven you can open the pdf with other apps, you can click retry in my app and it will still fail. Almost sounds like an operating system that will not allow my app get obtain any more file handles, but then my app can open other PDFs, so I don't think that is it.
Back to Top
waynefulcher View Drop Down
Senior Member
Senior Member
Avatar

Joined: 23 Jun 08
Location: United States
Status: Offline
Points: 99
Post Options Post Options   Thanks (0) Thanks(0)   Quote waynefulcher Quote  Post ReplyReply Direct Link To This Post Posted: 26 Apr 19 at 2:00AM
Can someone with access to the source code please help me? (Its the only way this can be resolved)

As mentioned before I have an app and after something (this is the mystery) causes my app to no longer be able to open certain PDFs. So when this unknown condition occurs and I call the following line of code:

    rc := PDF.LoadFromFile(PDFFileName, Password) ;

rc will equal 0, so I delay and then try again 3 times and every time rc equals 0 for certain PDfs.
After that I call 

PDF.LastErrorCode and this always return 401 which is "Documented" as Error opening file.

What I have basically determined is there is no reason the file cannot be opened. I can open it with external apps and I added code in my app to open that same file using a TFileStream right after I get the above error with QuickPDF and it works just fine.
So what I believe is happening is the actual problem is something else inside of QuickPDF like it is getting an exception and the default error code getting set is 401. Is there possibly an Error Message that might be set so I could get the exact exception message from inside QPF?

So here is what I need from someone who can look at the source code. I would like to know any of three possible things:

1. What would be the equivalent Delphi 7 code I could test to open the file exactly as the QuickPDF code does?

2. What would be other possibilities of something not working in QuickPDF.LoadFromFile() that might cause it to set LastErrorCode to 401? (For example: I read in an old thread where a PDF had an invalid header/version number and caused LoadFromFile to return a 401. So the error was not really error opening file. Those are the things I would be interested in knowing.

3. A way to get a meaningful and correct Error Message detailing what the last error actually was.

Thanks for any help anyone is willing to give me.




Back to Top
Ingo View Drop Down
Moderator Group
Moderator Group
Avatar

Joined: 29 Oct 05
Status: Offline
Points: 3524
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ingo Quote  Post ReplyReply Direct Link To This Post Posted: 26 Apr 19 at 10:34AM
Hi Wayne,


your issue description sounds more like there isn't properly cleaned up in memory in case of error.
Is your call inside from "try...finally...end" or "try... except...end"?
Is the LoadFromFile in a loop (read in a directory...) without a free and nil on the instance?
LoadFromFile (and other functions as well) returns only with a 0 or 1. This was the reason for function LastErrorCode (to have a more detailed error code) - so you won't find more specific codes in the source.
LastErrorCode delivers a lot:
https://www.debenu.com/docs/pdf_library_reference/LastErrorCode.php

Cheers,
Ingo

Back to Top
tfrost View Drop Down
Senior Member
Senior Member


Joined: 06 Sep 10
Location: UK
Status: Offline
Points: 437
Post Options Post Options   Thanks (0) Thanks(0)   Quote tfrost Quote  Post ReplyReply Direct Link To This Post Posted: 26 Apr 19 at 11:19AM
1. QPDF.LoadFromFile opens a filestream and then calls QPDF.LoadFromStream, so you can quickly eliminate all external/OS issues by doing the same yourself.

2. In version 16 there are 14 separate instances of assignments of 401 to LastErrorCode; none is associated with a more useful error message and most (other than the basic open failure) are preceded by "else" or "except", and thus represent "something really bad happened that we did not expect or allow for with a specific error code". And none of these would lead you to a problem that occurs randomly on the same file. 

3. There is little more that you can do without being able to reproduce the issue reliably in your own debugger, which you have already said cannot be done.

I agree with Ingo that the symptoms point inexorably to bad code somewhere else in your program, perhaps completely unrelated, such as a buffer overflow which causes an overwrite and modifies code consistently when it happens in specific circumstances. In addition there have been many small and large fixes in QPDF since v8, and in Delphi since v7.  Switching everything to use DA calls would use completely different ways of QPDF file loading so might avoid the problem for a while; or might simply cause a similar program corruption to show up somewhere else.
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.01
Copyright ©2001-2014 Web Wiz Ltd.

Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. AboutContactBlogSupportOnline Store