spiritix / php-chrome-html2pdf

A PHP library for converting HTML to PDF using Google Chrome
MIT License
112 stars 29 forks source link

call chrome directly without js code #4

Closed zerozh closed 6 years ago

zerozh commented 6 years ago

It seems calling chrome directly from php code is possible. What is the pros and cons of using js as gateway?

spiritix commented 6 years ago

It is definitely possible, yes. The problem is that there is no decent API available for PHP, therefore I'd need to write one which isn't really in the scope of this library. The guys from puppeteer have done an awesome job in wrapping all possible interactions down to the DevTools protocol, so the only advantage of repeating that for PHP would be to not be required to having Node installed on the server.

zerozh commented 6 years ago

https://bugs.chromium.org/p/chromium/issues/detail?id=603559#c51 As developer said, arguments in DevTools will not to be migrated to command line arguments. I prefer to use puppeteer to send arguments like displayHeaderFooter in printToPDF instead of connect to DevTools via websocket.

spiritix commented 6 years ago

Exactly, so one more reason to stick with DevTools and not use CLI of Chrome. What I don't understand is why you are using a Websocket at all? How is that related to Puppeteer and this library?

zerozh commented 6 years ago

https://bugs.chromium.org/p/chromium/issues/detail?id=603559#c48

You could write a small wrapper script (in any language with a WebSockets library) to wrangle the DevTools commands.

So your solution is perfect.

spiritix commented 6 years ago

All right, super.