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

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
prerendercloud
  .screenshot("http://example.com", {
    viewportWidth: 640,
    viewportHeight: 480,
    viewportX: 10,
    viewportY: 10
  })
  .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
prerendercloud
  .pdf("http://example.com", {
    noPageBreaks: true
  })
  .then(pdfBuffer => fs.writeFileSync("out.pdf", pdfBuffer, { encoding: null }));
Hosted on Roast.io