Sign inSign up

coderbhai/chrome-print

By coderbhai

•Updated about 6 years ago

Image
0

10K+

coderbhai/chrome-print repository overview

⁠chrome-print

A headless chrome process with an express-based API in front of it. Upload an HTML file, specify width and height, get a PDF back.

⁠Run

docker-compose up

⁠Usage

# get the port the server is listening on
port=`docker ps |grep chromeprint_print |sed 's/.*:\([0-9]*\)-.*/\1/'`

# send the request
curl \
  -F "[email protected]" \
  -F "width=8.5" \
  -F "height=11" \
  -X POST \
  -H "Content-Type: multipart/form-data" \
  -o test.pdf \
  http://localhost:$port/

# OR Send a URL

curl \
  -F "url=https://www.google.com/" \
  -F "width=8.5" \
  -F "height=11" \
  -X POST \
  -H "Content-Type: multipart/form-data" \
  -o test.pdf \
  http://localhost:$port/

⁠Options

See also https://chromedevtools.github.io/devtools-protocol/tot/Page/#method-printToPDF⁠

Name of paramDefault ValueDescription
htmlFileundefinedOne of htmlFile or url is required.
urlundefinedOne of htmlFile or url is required.
width8.5Width of page in inches
height11Height of page in inches
delayundefinedDelay in milliseconds to wait for JS/AJAX after page load.
marginBottom0Page bottom margin in inches
marginTop0Page top margin in inches
marginLeft0Page left margin in inches
marginRight0Page right margin in inches

⁠Attribution

I basically copied and adapted code from this guy⁠. My whole solution is obviously cobbled together from various slapped together sources, but it fits my needs.

Tag summary

Content type

Image

Digest

Size

394.2 MB

Last updated

about 6 years ago

docker pull coderbhai/chrome-print