hajareshyam / pdf-creator-node

This package is used to generate HTML to PDF in Nodejs
MIT License
238 stars 80 forks source link

Working on local but not as AWS Lambda code #111

Open lahoti-piyush opened 1 year ago

lahoti-piyush commented 1 year ago

AWS Lambda Runtime: Node.js 18.x

spawn /var/task/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe',
  path: '/var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe',
  spawnargs: [
    '--local-url-access=false',
    '--local-url-access=false',
    '/var/task/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js'
  ]
}
muhammadyusuf-kurbonov commented 1 year ago

It would help if you run npm rebuild on the server side to build phantomjs binaries for specific platforms. I have Linux VPS and it's helped me. P.s.: I've no experience with AWS Lambda, so I can't provide direct instructions.

Abutahir12 commented 1 year ago

you will need to add a phantom js binary and provide the path, along with that, you need to provide the path to pdf_a4_portrait.js file

childProcessOptions: {
      env: {
        OPENSSL_CONF: "/dev/null"
      }
    },
    localUrlAccess: true,
    phantomPath: "/opt/nodejs/executables/executables/phantomjs_linux-x86_64",
    script: "/opt/nodejs/executables/executables/scripts/pdf_a4_portrait.js"
   };

In my case I have added these files in the layer and provided the path, add the above configuration in options Try downloading the phantom js from here, make sure you download the correct file according to OS in your lambda environment https://phantomjs.org/download.html

junaidranjha commented 1 year ago

@lahoti-piyush did you find any solution?

martinGM05 commented 6 months ago

So ?, Did you find any solutions? 2024 :'(

lahoti-piyush commented 6 months ago

So ?, Did you find any solutions? 2024 :'(

yes, added a chromium-layer to lambda