Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to send html instead of url? #22

Open
pavle-lekic-htec opened this issue Sep 14, 2018 · 3 comments
Open

Possibility to send html instead of url? #22

pavle-lekic-htec opened this issue Sep 14, 2018 · 3 comments

Comments

@pavle-lekic-htec
Copy link

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.

@hairylime
Copy link

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...

@chilek
Copy link

chilek commented Jan 10, 2020

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.

@chilek
Copy link

chilek commented Jan 10, 2020

I reply for myself - it is possible, but required some quirk in the following line:

return url.match(/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-_]*)?\??(?:[\-\+=&;%@\.\w_]*)#?(?:[\.\!\/\\\w]*))?)/)

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants