Convert a URL to a PNG or PDF (Screenshots)#

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));

// 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));

// or specify viewport
prerendercloud
  .screenshot("http://example.com", {
    viewportWidth: 640,
    viewportHeight: 480,
    viewportX: 10,
    viewportY: 10
  })
  .then(pngBuffer => fs.writeFileSync("out.png", pngBuffer));

URL to PDF#

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

With cURL#

URL to PNG#

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

URL to PDF#

curl --compressed http://service.prerender.cloud/pdf/https://google.com/ > out.pdf
Hosted on Roast.io