We have a webpage that builds PDF documents based on individual PDF pages that are managed by the company. You can see the webpage here:
Ignoring the part that requires login, there are several manuals available in PDF format in the middle of the page. Each of these is built from individual PDF pages and concatenated using pdftk on the server, where PHP pulls what pages need to be included and executes a custom call to the pdftk command. The output of the pdftk command is placed in the site for downloading at each page load to ensure the most updated manuals are available. Currently, we are limiting the build to a small number of individual PDF pages, but if we were to allow all of the pages to be included, the page would never finish loading.
The problem lies in that PHP's use of the exec/passthru/system or any other function that allows access to server commands does not complete correctly. By this I mean that if the same PHP command is applied directly to the command line, i.e. "pdftk foo.pdf bob.pdf cat output manual.pdf", this command succeeds and the manual.pdf works fine. However, if the command is applied through the use of exec/passthru/etc via PHP, the command never finishes. The page will eventually time out and a look at the server's open processes show the pdftk command is running, although it takes only a second for the same command to complete via the command line.
The problem appears to occur when many individual PDF files are passed to pdftk, as we have no problem with up to around 10 or so files. If we include more (and there are more to be included), the process does not complete. However, we get different results when testing with a different number of files (i.e., we are always able to build up to 6-10 files, sometimes 11, never more than that at once) and the final output PDF cannot be more than 8 MB in size. These are just observations from our tests in trying to work this out. On the command line, there is no limitation or issue with many individual PDF pages, the problem only occurs when PHP is brought into the picture.
I have attempted to contact the pdftk team, no response, so I hope someone here can point us in the right direction.
My question is two-fold. Why would the use of exec/system/etc via PHP be any different than passing the exact same string to the command-line? What can I look into to figure out what is happening on the PHP side of things?
Second, is there any PHP library that we can use in place of pdftk to concatenate individual PDF files into one file available for download where we might be able to workaround this problem? Or does anyone have an alternative suggestion that will meet the requirements of building custom PDF files based on individual pages managed separately?
Thanks in advance for any advice or assistance you can provide.