wubzz / pdf-merge

Merge multiple PDF Files into a single PDF document
127 stars 32 forks source link

Command failed: pdftk #20

Closed wlodi83 closed 7 years ago

wlodi83 commented 7 years ago

Hi,

I am trying to merge 2 pdf files test0.pdf and test1.pdf into fullpdf.pdf document but I am getting following error. I use Debian jessie. It works on MacOSX.

2017-09-27T09:54:07.188647414Z File: test0.pdf 2017-09-27T09:54:07.188650457Z File: test1.pdf 2017-09-27T09:54:07.188653004Z outputFile: /home/exports/fullpdf.pdf 2017-09-27T09:54:07.241490286Z [error] PDF merge error: { Error: Command failed: pdftk '/home/exports/test0.pdf' '/home/exports/test1.pdf' cat output /home/github/reports/tmp-33gt0sQwChMCeV 2017-09-27T09:54:07.241516080Z Error: Unable to find file. 2017-09-27T09:54:07.241520060Z Error: Failed to open PDF file: 2017-09-27T09:54:07.241522866Z /home/exports/test1.pdf 2017-09-27T09:54:07.241525757Z Errors encountered. No output created. 2017-09-27T09:54:07.241528539Z Done. Input errors, so no output created. 2017-09-27T09:54:07.241531101Z 2017-09-27T09:54:07.241533638Z at ChildProcess.exithandler (child_process.js:198:12) 2017-09-27T09:54:07.241536298Z at emitTwo (events.js:106:13) 2017-09-27T09:54:07.241538806Z at ChildProcess.emit (events.js:191:7) 2017-09-27T09:54:07.241549407Z at maybeClose (internal/child_process.js:920:16) 2017-09-27T09:54:07.241552167Z at Process.ChildProcess._handle.onexit (internal/child_process.js:230:5)

wubzz commented 7 years ago

I just tried this on debian 8 on 1.0.2 and it works as expected. Can you provide more details?

wlodi83 commented 7 years ago

I use Debian GNU/Linux 8 with pdftk 2.02.

NodeJS: v6.11.3

Here is my example code:

//Adding files for merge statement to pdfFiles array //Download files from S3 let pdfFiles = []; for (let pdfFile of files_to_merge) { let uniqueKey = Math.random().toString(36).substr(2, 16); await makeGetRequest(pdfFile.s3Url, uniqueKey); pdfFiles.push(${HOME_FOLDER}/${uniqueKey}.pdf); };

//Merge downloaded files into ${timestamp}_fullpdf.pdf let date = new Date(); let timestamp = date.getTime(); let outputFile = ${HOME_FOLDER}/${timestamp}_fullpdf.pdf; await PDFMerge(pdfFiles, {output: outputFile});

wubzz commented 7 years ago

@wlodi83 Don't see anything 'weird' at first glance.. The external library is complaining about the files not existing. Are you sure they are being written to the same path that the pdfFiles array is getting?

Could rule this out by logging the output right after await makeGetRequest console.log(`${uniqueKey}.pdf exists?`, require('fs'.existsSync(`${HOME_FOLDER}/${uniqueKey}.pdf`))

wlodi83 commented 7 years ago

Yes, file exists.

2017-09-27T13:44:47.160886324Z File: nq9qdjjpnte38a5y.pdf 2017-09-27T13:44:47.160937585Z File: ywyrt4tquzv34v3p.pdf 2017-09-27T13:44:47.161001897Z outputFile: /home/exports/1506519887160_fullpdf.pdf 2017-09-27T13:44:47.250010386Z [error] PDF merge error: { Error: Command failed: pdftk '/home/exports/ywyrt4tquzv34v3p.pdf' '/home/exports/nq9qdjjpnte38a5y.pdf' cat output /home/github/reports/tmp-355YsHYjhEbWmC

wubzz commented 7 years ago

From the log in the first post:

Log

2017-09-27T09:54:07.241520060Z Error: Failed to open PDF file:
2017-09-27T09:54:07.241522866Z /home/exports/test1.pdf

Command pdftk '/home/exports/test0.pdf' '/home/exports/test1.pdf' cat output /home/github/reports/tmp-33gt0sQwChMCeV

PDFtk complains about test1.pdf but not test0.pdf, and test0.pdf should most likely have been parsed first..

Unfortunately since I can't reproduce this myself and the error is outside the PDFMerge library code I'm not so sure I can help.

wlodi83 commented 7 years ago

Yes, problem was with the file. It was somehow not created. Thanks for your help.