subhamX / notion-easy-export

📘 Notion easy export converts your notion documents & databases into an ebook.
https://www.npmjs.com/package/notion-easy-export
Apache License 2.0
63 stars 4 forks source link

Failing when converting to pdf #1

Closed malikshubham827 closed 2 years ago

malikshubham827 commented 2 years ago

Hi, I was just giving the project a try but its failing at the last step of converting html to pdf. Logs:

info: Saving Ebook at [/Users/shubhammalik/utils/notion-to-pdf/session_files/output/merged/prime_book.pdf]
/Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/bin/wkhtmltopdf/wkhtmltopdf: /Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/bin/wkhtmltopdf/wkhtmltopdf: cannot execute binary file
error: main: Error: Command failed: /Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/bin/wkhtmltopdf/wkhtmltopdf --enable-local-file-access --margin-bottom 10 --margin-top 15 --header-spacing 5 --header-html /Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/assets/header/index.html cover /Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/assets/cover/index.html toc --xsl-style-sheet /Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/assets/toc/styles.xls /Users/shubhammalik/utils/notion-to-pdf/session_files/tmp/tmp.html /Users/shubhammalik/utils/notion-to-pdf/session_files/output/merged/prime_book.pdf
/Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/bin/wkhtmltopdf/wkhtmltopdf: /Users/shubhammalik/utils/notion-to-pdf/node_modules/@subhamx/notion-to-ebook/bin/wkhtmltopdf/wkhtmltopdf: cannot execute binary file
subhamX commented 2 years ago

Hi, @malikshubham827; thank you for reporting the issue. Could you please share the operating system you are using? So far, I have tested it only on Linux. I had planned to include the executable of wkhtmltopdf for windows and mac, but then dropped the plan to keep the bundle size small (it's already 40+ MB 😰). Let me explore some ways to tackle this problem of os dependent dependencies (after end-sem 😅)! So far, I can only think of having a post-install script to fetch the right binary files based on OS! (But this isn't a good practice). In the worst case, we shall include all the binaries! (let's hope not!🤞) If you find any solution feel free to share it or post a PR.

mikolasan commented 2 years ago

The same thing on Windows 10:

$ node index.js
info: Starting operation
info: Removing all files in session Files Dir!!!
info: Creating directories in session Files Dir!!!
info: Starting Html Export Subroutine
info: Task Id: c21b1ca8-c332-43d1-b55b-26ed6790577a
info: Current Task status: success
info: Got the S3 download URL
info: Starting file download
info: File download successful
info: Removing all non dot files and folders from C:\Users\neupo\develop\ebook\session_files\input
info: Files removal success
info: Starting file extraction
info: File extracted successfully
info: Saving the output file as HTML at tmp location
info: Exporting the HTML To Ebook
info: Saving Ebook at [C:\Users\neupo\develop\ebook\session_files\output\merged\prime_book.pdf]
error: main: Error: spawnSync C:\Users\neupo\develop\ebook\node_modules\@subhamx\notion-to-ebook\bin\wkhtmltopdf\wkhtmltopdf ENOENT
Done in 7.81s.

Last step fails and no pdf. No conversion tool wkhtmltopdf obviously.

I think @subhamX should remove the bin folder and instead add to the readme file this text (copied from https://www.npmjs.com/package/wkhtmltopdf)

First, you need to install the wkhtmltopdf command line tool on your system.

The easiest way to do this is to download a prebuilt version for your system. DO NOT try to use the packages provided by your distribution as they may not be using a patched Qt and have missing features.

subhamX commented 2 years ago

@mikolasan It makes sense. Let me give another try to fix the issue with conditional check on the type of OS and then downloading the relevant binary from upstream. If not we will go with the logic you mentioned above.

subhamX commented 2 years ago

Unfortunately, I couldn't find a simple way of installing wkhtmltopdf by getting the hardware architectures, OS distributions, and their version. And even if I could build a post-build script there is no way for me to test it on all of these permutations. 😥

So finally went with the approach as suggested by @mikolasan and left the wkhtmltopdf installation part to users. Additional check to ensure that wkhtmltopdf is present in PATH is also included.

Closing this issue for now! Thank you @mikolasan and @malikshubham827 for your valuable inputs 😃. (And my apologies for the late actions).