marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 543 forks source link

Cant open pdf_a4_portrait.js inside app.asar #424

Open zer09 opened 6 years ago

zer09 commented 6 years ago

Hello good day,

I am unable to create pdf files if I will enable the asar on the electron-builder.

When tried to execute it I am getting this error.

C:\Users\gust 7\AppData\Local\Programs\ex\resources\app.asar\app\methods.js:1388 Error: html-pdf: Received the exit code '4294967295'
Can't open 'C:\Users\gust 7\AppData\Local\Programs\ex\resources\app.asar\node_modules\html-pdf\lib\scripts\pdf_a4_portrait.js'

    at ChildProcess.respond (C:\Users\gust 7\AppData\Local\Programs\ex\resources\app.asar\node_modules\html-pdf\lib\pdf.js:121)
    at emitTwo (events.js:125)
    at ChildProcess.emit (events.js:213)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:200)

I will greatly appreciate, any advice will come.

thanks.

akasselman commented 6 years ago

I suspect the space in your path (gust_7) might be causing a problem, as this is a common problem for files not being "found" when trying to open them. Perhaps you could try wrapping your path string (C:\Users\gust 7\AppData\Local\Programs\ex\resources\app.asar\node_modules\html-pdf\lib\scripts\pdf_a4_portrait.js) in double quotes, or remove the space?

zer09 commented 6 years ago

I tried to create new user without spaces on the name, but I still got the same error.

Jucesr commented 6 years ago

I am having the same Issue.

Trying to integrate it with pkg. Any news?

Error: html-pdf: Received the exit code '4294967295'
Can't open 'C:\snapshot\user_log\node_modules\html-pdf\lib\scripts\pdf_a4_portrait.js'

    at ChildProcess.respond (C:\snapshot\user_log\node_modules\html-pdf\lib\pdf.js:121:31)
    at emitTwo (events.js:126:13)
    at ChildProcess.emit (events.js:214:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
Karzeus commented 6 years ago

I have the exact same problem as you, @Jucesr using pkg. Did you find a way to solve this?

Jucesr commented 6 years ago

Hey @Karzeus

I was able to fix it by including the complete path to the file in the option object.

const pdf_options = { 
            format: 'Letter',
            header: {
                height: "20mm"
              },
            footer: {
                height: "15mm"
            },
            script: path.join(pathToFile, 'pdf_a4_portrait.js')
        }
luki06 commented 5 years ago

Hi First try to unpack the html-pdf module like "electron-packager . test--overwrite --asar.unpackDir=node_modules/html-pdf " and use the method provided by @Karzeus but change the script path to "path.join(__dirname,'node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js').replace('app.asar\src', 'app.asar.unpacked');",that should work goodluck.