Convert a URL to a PNG or PDF#

With cURL#

URL to PNG#

curl --compressed https://service.prerender.cloud/screenshot/https://google.com > out.png

URL to PDF#

curl --compressed https://service.prerender.cloud/pdf/https://google.com > out.pdf

Options#

Set screenshot and PDF options via HTTP headers, with cURL this would look like:

curl --compressed --header 'Prerender-Emulated-Media: print' https://service.prerender.cloud/screenshot/https://google.com

(and yes you should always use --compressed flag (which is just gzip))

other options:

With Node.js#

Install Node.js client lib#

$ npm install prerendercloud --save

source code: https://github.com/sanfrancesco/prerendercloud-nodejs#screenshots

URL to PNG#

const prerendercloud = require('prerendercloud');
// prerendercloud.set('prerenderToken', 'mySecretToken')
prerendercloud
  .screenshot("http://example.com")
  .then(pngBuffer => fs.writeFileSync("out.png", pngBuffer, { encoding: null }));

// or specify DOM selector to take a screenshot of a specific element
prerendercloud
  .screenshot("http://example.com", {
    viewportQuerySelector: '#open-graph-div',
    viewportQuerySelectorPadding: 10,
  })
  .then(pngBuffer => fs.writeFileSync("out.png", pngBuffer, { encoding: null }));

// or specify viewport and/or emulated media
prerendercloud
  .screenshot("http://example.com", {
    viewportWidth: 640,
    viewportHeight: 480,
    viewportX: 10,
    viewportY: 10,
    emulatedMedia: 'screen' // screen is the default for screenshots, you can change to print
  })
  .then(pngBuffer => fs.writeFileSync("out.png", pngBuffer, { encoding: null }));

URL to PDF#

const prerendercloud = require('prerendercloud');
// prerendercloud.set('prerenderToken', 'mySecretToken')
prerendercloud
  .pdf("http://example.com")
  .then(pdfBuffer => fs.writeFileSync("out.pdf", pdfBuffer, { encoding: null }));

// optionally disable page breaks and/or emulated media
prerendercloud
  .pdf("http://example.com", {
    noPageBreaks: true,
    emulatedMedia: 'print' // print is the default for PDFs, you can change to screen
  })
  .then(pdfBuffer => fs.writeFileSync("out.pdf", pdfBuffer, { encoding: null }));
Hosted on Roast.io