karuppiah7890 / easy-pdf-merge

An npm module to merge PDFs. https://www.npmjs.com/package/easy-pdf-merge [ CURRENTLY NOT MAINTAINED ]
85 stars 37 forks source link

Command failed: root cannot be null #15

Open deepuab opened 5 years ago

deepuab commented 5 years ago

I m getting below error while trying to merge pdfs using the package

{ Error: Command failed: java -jar  "/opt/ocr-service/node_modules/easy-pdf-merge/jar/pdfbox.jar" PDFMerger "/tmp/tesseract_dir_17ku4292IFSc57/tess_input_dir_17zzk1qPz3T7pb/P0001.pdf" "/tmp/tesseract_dir_17ku4292IFSc57/tess_input_dir_17k4Ki0xeLWNhR/P0002.pdf" "/tmp/tesseract_dir_17ku4292IFSc57/tess_input_dir_17gd2ZIeIKuaQI/P0003.pdf" "/tmp/tesseract_dir_17ku4292IFSc57/MergedPdf.pdf"
Exception in thread "main" java.lang.IllegalArgumentException: root cannot be null
    at org.apache.pdfbox.pdmodel.PDPageTree.<init>(PDPageTree.java:75)
    at org.apache.pdfbox.pdmodel.PDDocumentCatalog.getPages(PDDocumentCatalog.java:132)
    at org.apache.pdfbox.multipdf.PDFMergerUtility.appendDocument(PDFMergerUtility.java:733)
    at org.apache.pdfbox.multipdf.PDFMergerUtility.legacyMergeDocuments(PDFMergerUtility.java:381)
    at org.apache.pdfbox.multipdf.PDFMergerUtility.mergeDocuments(PDFMergerUtility.java:280)
    at org.apache.pdfbox.tools.PDFMerger.merge(PDFMerger.java:70)
    at org.apache.pdfbox.tools.PDFMerger.main(PDFMerger.java:49)
    at org.apache.pdfbox.tools.PDFBox.main(PDFBox.java:81)

    at ChildProcess.exithandler (child_process.js:294:12)
    at ChildProcess.emit (events.js:189:13)
    at ChildProcess.EventEmitter.emit (domain.js:441:20)
    at maybeClose (internal/child_process.js:970:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
  killed: false,
  code: 1,
  signal: null,
  cmd:
   'java -jar  "/opt/ocr-service/node_modules/easy-pdf-merge/jar/pdfbox.jar" PDFMerger "/tmp/tesseract_dir_17ku4292IFSc57/tess_input_dir_17zzk1qPz3T7pb/P0001.pdf" "/tmp/tesseract_dir_17ku4292IFSc57/tess_input_dir_17k4Ki0xeLWNhR/P0002.pdf" "/tmp/tesseract_dir_17ku4292IFSc57/tess_input_dir_17gd2ZIeIKuaQI/P0003.pdf" "/tmp/tesseract_dir_17ku4292IFSc57/MergedPdf.pdf"' } }
GoodLadCarlos commented 5 years ago

I'm having the same issue. It works when you do the "node yourscript.js" on terminal but when I compiled it using the pkg and run the .exe file it shows this error:

{ Error: Command failed: java -jar "C:\snapshot\DakabiApp\node_modules\easy-pdf-merge\jar\pdfbox.jar" PDFMerger "_temp/temp01558608247085.pdf" "_temp/temp11558608247106.pdf" "_temp/combined.pdf" Error: Unable to access jarfile C:\snapshot\DakabiApp\node_modules\easy-pdf-merge\jar\pdfbox.jar at ChildProcess.exithandler (child_process.js:281:12) at emitTwo (events.js:126:13) at ChildProcess.emit (events.js:214:7) at maybeClose (internal/child_process.js:915:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5) killed: false, code: 1, signal: null, cmd: 'java -jar "C:\snapshot\DakabiApp\node_modules\easy-pdf-merge\jar\pdfbox.jar" PDFMerger "_temp/temp01558608247085.pdf" "_temp/temp11558608247106.pdf" "_temp/combined.pdf"' }

Even though the pdfbox.jar exists inside the node_modules, it appears that the said file is missing after compiling using pkg.

karuppiah7890 commented 5 years ago

@GoodLadCarlos could you please explain what you mean when you say you compiled it using the pkg and ran the exe?

karuppiah7890 commented 5 years ago

@GoodLadCarlos And I think the issue posted by @deepuab is different as I see a different error. May be you could raise a different issue and continue the conversation there :)

GoodLadCarlos commented 5 years ago

@karuppiah7890 If I am not mistaken, I believe that @deepuab and I are using the same compiler "package or pkg" to convert the script into a desktop application. For example:

I still have an option to create my app and having the easy-pdf-merge on electron instead of pkg and see if Im still having the same issue. check this pkg reference

Thank you

GoodLadCarlos commented 5 years ago

@karuppiah7890 I replicate my app and compile it using electron-packager and run it. Im still having the same issue:

{ Error: Command failed: java -jar "C:\Users\Cyle Jose Aguinaldo\Desktop\electron-app\release-builds\app-clerk-win32-ia32\resources\app.asar\node_modules\easy-pdf-merge\jar\pdfbox.jar" PDFMerger "_temp/temp01558789281246.pdf" "_temp/temp11558789281302.pdf" "_temp/temp21558789281304.pdf" "_temp/temp31558789281305.pdf" "_temp/temp41558789281305.pdf" "_temp/temp51558789281306.pdf" "_temp/temp61558789281306.pdf" "_temp/combined.pdf" Error: Unable to access jarfile C:\Users\Cyle Jose Aguinaldo\Desktop\electron-app\release-builds\app-clerk-win32-ia32\resources\app.asar\node_modules\easy-pdf-merge\jar\pdfbox.jar at ChildProcess.exithandler (child_process.js:308:12) at ChildProcess.emit (events.js:194:13) at maybeClose (internal/child_process.js:998:16) at Process.ChildProcess._handle.onexit (internal/child_process.js:265:5) killed: false, code: 1, signal: null, cmd: 'java -jar "C:\Users\Cyle Jose Aguinaldo\Desktop\electron-app\release-builds\app-clerk-win32-ia32\resources\app.asar\node_modules\easy-pdf-merge\jar\pdfbox.jar" PDFMerger "_temp/temp01558789281246.pdf" "_temp/temp11558789281302.pdf" "_temp/temp21558789281304.pdf" "_temp/temp31558789281305.pdf" "_temp/temp41558789281305.pdf" "_temp/temp51558789281306.pdf" "_temp/temp61558789281306.pdf" "_temp/combined.pdf"' }

This time the script cant access the pdfbox.jar inside the app.asar. I'm still finding another way for a solution. I will let you know if there's a progress. Thanks

karuppiah7890 commented 5 years ago

@GoodLadCarlos Thanks for the context. I will have to reproduce the issue and see what's causing it, may be check what pkg, or electron does to do the packaging. I did create a demo electron app with this - https://github.com/karuppiah7890/pdf-merger-app .

It's been long since I worked in these projects. I will try to put some effort and try to help with this.

Other than this, I have also had thoughts of how using a npm module behind the scenes, instead of PDFBox (which requires a jar and java to be installed) will help. A colleague suggested the idea, talking about https://github.com/foliojs/pdfkit and another library. But having a glance at them looks like they don't provide the feature of merging PDFs, may be I need to spend more time on it. But on digging further, I found some good libs, one of them is https://www.npmjs.com/package/pdf-lib and some more are mentioned in the same page - https://www.npmjs.com/package/pdf-lib#prior-art .

But we will have to come up with Pros and Cons of such a solution (not using an external thing like PDFBox behind the scenes) and try to keep it completely JS and also see the feasibility of it. And I think PDFBox is surely great, and probably mature, coming from Apache and I think it's been in development for years, so replacing it means the npm module should provide good enough features with no issues. Probably a big call. May be we can raise a RFC issue and discuss it. cc @g0ddish (the current maintainer)

uzair4100 commented 4 years ago

@GoodLadCarlos @deepuab ...I am facing same issue.I was able to merge files when i was running app from terminal, but after I packaged it I get same error when merging files. Could you please help me ?

deepuab commented 4 years ago

@uzair4100 One of the pdfs which i tried to merge was corrupted. It was issue with my pdf generation logic. The merge issue got resolved when i removed the error pdf from merge.

uzair4100 commented 4 years ago

but i am still getting this error

Error: Command failed: java -jar "C:\Users\uzaira\AppData\Local\Programs\pdf-application\resources\app.asar\node_modules\easy-pdf-merge\jar\pdfbox.jar" PDFMerger "C:\Users\uzaira\Desktop\Student_Files\coverLetter\CHI_SL_Y9_1_CB_1.pdf.(06 student name) .pdf" "C:\Users\uzaira\Desktop\Student_Files\coursebooks\CHI_SL_Y9_1_CB_1.pdf" "C:\Users\uzaira\Desktop\Student_Files\readytoprint/(06 student name) .pdf" Error: Unable to access jarfile C:\Users\uzaira\AppData\Local\Programs\pdf-application\resources\app.asar\node_modules\easy-pdf-merge\jar\pdfbox.jar

at ChildProcess.exithandler (child_process.js:308)
at ChildProcess.emit (events.js:210)
at maybeClose (internal/child_process.js:1021)
at Process.ChildProcess._handle.onexit (internal/child_process.js:283)

It works fine when I run app with "npm start" from terminal.It gives me error when I package app using electron builder and try to merge pdf's.