phantom-html-to-pdf icon indicating copy to clipboard operation
phantom-html-to-pdf copied to clipboard

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

Open atljoseph opened this issue 7 years ago • 2 comments

atljoseph avatar Sep 18 '17 23:09 atljoseph

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.

bjrmatos avatar Sep 19 '17 15:09 bjrmatos

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 [email protected] 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 .

atljoseph avatar Oct 05 '17 01:10 atljoseph