Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

screenshotmachine

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

screenshotmachine

Captures website screenshot and converts website to PDF using Screenshot machine - online website screenshot generator and website to PDF converter

  • 2.0.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
20
increased by100%
Maintainers
1
Weekly downloads
 
Created
Source

screenshotmachine-nodejs

Captures website screenshot and converts website to PDF using Screenshot machine - online website screenshot generator and website to PDF converter

Installation

Install Node.js package:

npm install screenshotmachine --save

First, you need to create a free/premium account at www.screenshotmachine.com website. After registration, you will see your customer key in your user profile. Also secret phrase is maintained here. Please, use secret phrase always, when your API calls are called from publicly available websites.

Set-up your customer key and secret phrase (if needed) in the script:

var customerKey = 'PUT_YOUR_CUSTOMER_KEY_HERE';
    secretPhrase = ''; //leave secret phrase empty, if not needed

Website screenshot API

Set additional options to fulfill your needs:

    options = {
      //mandatory parameter
      url : 'https://www.google.com',
      // all next parameters are optional, see our website screenshot API doc for more details
      dimension : '1366xfull', // or "1366xfull" for full length screenshot
      device : 'desktop',
      format: 'png',
      cacheLimit: '0',
      delay: '200',
      zoom: '100'
    }

More info about options can be found in our Website screenshot API.

Sample code

var screenshotmachine = require('screenshotmachine');

var customerKey = 'PUT_YOUR_CUSTOMER_KEY_HERE';
    secretPhrase = ''; //leave secret phrase empty, if not needed
    options = {
      //mandatory parameter
      url : 'https://www.google.com',
      // all next parameters are optional, see our website screenshot API guide for more details
      dimension : '1366xfull', // or "1366xfull" for full length screenshot
      device : 'desktop',
      format: 'png',
      cacheLimit: '0',
      delay: '200',
      zoom: '100'
    }

var apiUrl = screenshotmachine.generateScreenshotApiUrl(customerKey, secretPhrase, options);

//put link to your html code
console.log('<img src="' + apiUrl + '">');  

Generated apiUrl link can be placed in <img> tag or used in your business logic later.

If you need to store captured screenshot as an image, just call:

var screenshotmachine = require('screenshotmachine');

var customerKey = 'PUT_YOUR_CUSTOMER_KEY_HERE';
    secretPhrase = ''; //leave secret phrase empty, if not needed
    options = {
      //mandatory parameter
      url : 'https://www.google.com',
      // all next parameters are optional, see our website screenshot API guide for more details
      dimension : '1366xfull', // or "1366xfull" for full length screenshot
      device : 'desktop',
      format: 'png',
      cacheLimit: '0',
      delay: '200',
      zoom: '100'
    }

var apiUrl = screenshotmachine.generateScreenshotApiUrl(customerKey, secretPhrase, options);

//save screenshot as an image
var fs = require('fs');
var output = 'output.png';
screenshotmachine.readScreenshot(apiUrl).pipe(fs.createWriteStream(output).on('close', function() {
  console.log('Screenshot saved as ' + output);
}));

Captured screenshot will be saved as output.png file in current directory.

Website to PDF API

Set the PDF options:

    options = {
      //mandatory parameter
      url : 'https://www.google.com',
      // all next parameters are optional, see our website to PDF API guide for more details
      paper : 'letter',
      orientation : 'portrait',
      media: 'print',
      bg: 'nobg',
      delay: '2000',
      scale: '50'
    }

More info about options can be found in our Website to PDF API.

Sample code
var screenshotmachine = require('screenshotmachine');

var customerKey = 'PUT_YOUR_CUSTOMER_KEY_HERE';
    secretPhrase = ''; //leave secret phrase empty, if not needed
    options = {
      //mandatory parameter
      url : 'https://www.google.com',
      // all next parameters are optional, see our website to PDF API guide for more details
      paper : 'letter',
      orientation : 'portrait',
      media: 'print',
      bg: 'nobg',
      delay: '2000',
      scale: '50'
    }

var pdfApiUrl = screenshotmachine.generatePdfApiUrl(customerKey, secretPhrase, options);

//save PDF file
var fs = require('fs');
var output = 'output.pdf';
screenshotmachine.readScreenshot(pdfApiUrl).pipe(fs.createWriteStream(output).on('close', function() {
  console.log('Pdf saved as ' + output);
}));

Captured PDF will be saved as output.pdf file in the current directory.

License

The MIT License (MIT)

Keywords

FAQs

Package last updated on 26 Aug 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc