Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Pdftk.exe -- permissions issues when deleting generated PDFs

Posted on 2011-10-03
Medium Priority
Last Modified: 2012-05-12
I am using the common PDF command line program, pdftk.exe, to generated custom-made PDFs with variable data. In time, there is a need to delete some of these, for which I am using the PHP unlink() function.

Every once in a while, one rogue PDF that has been generated from pdftk.exe (called from the same PHP program) coughs up some permissions issues, keeping it from being deleted. I am perplexed because it is only this one rogue one once in a while, and all the others delete just fine. I also don't think it is an issue with the specific BASE pdf used to generate the one with variable data, because I know I have successfully deleted some generated from that same base PDF.

Can you clue me in? What could be causing this just once in a while? There are very few clues, and like I said the base PDF doesn't appear to be a key to the cause.
Question by:jristov
  • 2
LVL 111

Expert Comment

by:Ray Paseur
ID: 36908908
Permissions issues are usually driven by the interplay of a program, a file system and an operating system.  If you want to tell us a little more about those things we might be able to offer some help.  The situation you describe might be driven by a chmod() statement in a conditional control structure.
LVL 44

Accepted Solution

Karl Heinz Kremer earned 2000 total points
ID: 36909404
Is it possible that the file that you want to remove is actually in use (e.g. open in Reader or any other application, or being served by the web server)?

Author Comment

ID: 36911650
khkremer: Yes, it appears you have hit the nail right on the head! Thank you! But, a related question that pops up is: How do I know if this file is currently open or being used somewhere? Is there a way in PHP to know this (perhaps through an "error handler" that returns the permission denied error)?
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 36912395
It looks like you are using Windows (based on the .exe extension to pdftk), this is not a platform I am very familiar with.

The unlink() function returns a boolean: TRUE on success and FALSE on failure. You should evaluate that return value to see if your unlink call was successful. I would hope that it reports a problem if the call fails due to the busy condition. Usually (again, this may not be valid for Windows), you can move a file that is open, so you could just move it out of the way, and then when in certain intervals process the "these files were in use at one point in time, but should be deleted" directory and try to delete the files in it.


Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question