pofider / phantom-html-to-pdf

Highly scalable html to pdf conversion using phantom workers
MIT License
159 stars 33 forks source link

Would like to be able to inject css as well as js #78

Open atljoseph opened 7 years ago

bjrmatos commented 7 years ago

hi! i see that it can be a nice feature to add, probably it can be a good excuse to send us a PR and collaborate in the project 😄 .. you can take a look at the implementation of injectJs, as you can see it is not very difficult to add something like that because it uses a built-in phantomjs method called injectJs too. for the case of injecting css there is no built-in phantomjs for that, but it can be replicated, you would need to receive an array of css filenames, then read the content of each one and save it in an array with the content of each file, and then add all the contents using a combination of phantomjs's onInitialized event and the phantomjs's evaluate method, in the phantomjs's evaluate method you would need some javascript that creates and insert to the DOM a style tag for each file in your array of contents.

atljoseph commented 7 years ago

Thanks man, yeah send me an invite if you like. I ended up limiting the scope of supported CSS files to just a few files which were pre-installed on the server and just passing the filename in the converted html's document head as a stylesheet link with a unique moniker inside the path which was replaced with a local file:/// call to the target css file. Joseph

On Tue, Sep 19, 2017 at 11:34 AM, BJR Matos notifications@github.com wrote:

hi! i see that it can be a nice feature to add, probably it can be a good excuse to send us a PR and collaborate in the project 😄 .. you can take a look at the implementation of injectJs https://github.com/pofider/phantom-html-to-pdf/pull/46/files, as you can see it is not very difficult to add something like that because it uses a built-in phantomjs method called injectJs too http://phantomjs.org/api/webpage/method/inject-js.html. for the case of injecting css there is no built-in phantomjs for that, but it can be replicated, you would need to receive an array of css filenames, then read the content of each one and save it in an array with the content of each file, and then add all the contents using a combination of phantomjs's onInitialized event and the phantomjs's evaluate method http://phantomjs.org/api/webpage/handler/on-initialized.html, in the phantomjs's evaluate method you would need some javascript that creates and insert to the DOM a style tag for each file in your array of contents.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pofider/phantom-html-to-pdf/issues/78#issuecomment-330577000, or mute the thread https://github.com/notifications/unsubscribe-auth/AX29FZx60Utb14tW_YZrOr4yBwSB5GpPks5sj92WgaJpZM4Pbrgy .