Last active
April 5, 2019 18:34
-
-
Save vbarbarosh/a291ebf78a093c415ba4b189219a7a3d to your computer and use it in GitHub Desktop.
shell_docker_browserless_htmlpdf – Convert html to pdf using Browserless https://codescreens.com
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # http://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin | |
| # http://redsymbol.net/articles/unofficial-bash-strict-mode/ | |
| set -o nounset -o errexit -o pipefail | |
| # usage: cat input.html | ./shell_docker_browserless_htmlpdf > a.pdf | |
| html=`base64 -w0` | |
| docker run --rm -i browserless/chrome bash << EOF | |
| node build/index.js & | |
| sleep 1 | |
| node > a << 'EOF2' | |
| const code = \` | |
| module.exports = async function (v) { | |
| await v.page.setContent(v.context.html); | |
| return {data: await v.page.pdf()}; | |
| }; | |
| \`; | |
| const context = {html: new Buffer('$html', 'base64').toString()}; | |
| console.log(JSON.stringify({code, context})); | |
| EOF2 | |
| curl 127.0.0.1:3000/function -H Content-Type:application/json \ | |
| -o /dev/stdout -sf -d@a | |
| EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment