pdf-bot
pdf-bot copied to clipboard
Possibility to send html instead of url?
Hi, Thanks for the wonderful library and all the effort that you invested. I have a situation where I'd prefer to send raw html to the bot and get back pdf in return, so no urls just html in POST request, is that possible? Thanks.
FYI - did a little digging and found that the underlying library accepts data urls, so if you take your html, base64 encode it and then request pdf-bot with a url of data:text/html;base64,<your encoded html here>
it will do what you're looking for...
Hi, I tried to convert local file using file
protocol:
$ pdf-bot push 'file://full/path/contract.html'
The job was created with ID 82a0112d-7eaa-474a-8b4c-d13ee6a8ec4a
$ pdf-bot shift:all
Found 1 jobs, divided into 1 chunks
Running chunk 1, 0 chunks left
html-pdf-chrome error: Error: HtmlPdf.create() page navigate failed. (job ID: 82a0112d-7eaa-474a-8b4c-d13ee6a8ec4a. Generation ID: 746d2054-267e-4e85-ab46-19d900b5b20c)
As you see above it generates error. How you can point local file name for pdf-bot?
http
, https
and data
work.
I reply for myself - it is possible, but required some quirk in the following line: https://github.com/esbenp/pdf-bot/blob/a2edd1ea570b840965e980c0900c5aaa27d80148/src/utils.js#L2 Should be:
var isValidUrl = function (url) {
return url.match(/(((file:\/|[A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/)
}
because for file
protocol root directory for full path should contain single slash character as google-chrome headless seems to have such requirement.