screenshotmachine
Advanced tools
Comparing version 1.1.1 to 2.0.0
@@ -8,3 +8,3 @@ var screenshotmachine = require('screenshotmachine'); | ||
url : 'https://www.google.com', | ||
// all next parameters are optional, see our API guide for more details | ||
// all next parameters are optional, see our website screenshot API guide for more details | ||
dimension : '1366xfull', // or "1366xfull" for full length screenshot | ||
@@ -18,3 +18,3 @@ device : 'desktop', | ||
var apiUrl = screenshotmachine.generateApiUrl(customerKey, secretPhrase, options); | ||
var apiUrl = screenshotmachine.generateScreenshotApiUrl(customerKey, secretPhrase, options); | ||
@@ -21,0 +21,0 @@ //put link to your html code |
14
index.js
var request = require('request'), | ||
crypto = require('crypto'); | ||
var screenshotBaseUrl = 'https://api.screenshotmachine.com/?'; | ||
var pdfBaseUrl = 'https://pdfapi.screenshotmachine.com/?'; | ||
module.exports.generateApiUrl = function(customerKey, secretPhrase, options) { | ||
var apiUrl = 'https://api.screenshotmachine.com/?key=' + customerKey; | ||
module.exports.generateScreenshotApiUrl = function(customerKey, secretPhrase, options) { | ||
return generateUrl(screenshotBaseUrl, customerKey, secretPhrase, options); | ||
} | ||
module.exports.generatePdfApiUrl = function(customerKey, secretPhrase, options) { | ||
return generateUrl(pdfBaseUrl, customerKey, secretPhrase, options); | ||
} | ||
function generateUrl(baseUrl, customerKey, secretPhrase, options) { | ||
var apiUrl = baseUrl + 'key=' + customerKey; | ||
if (secretPhrase != null && secretPhrase.trim().length > 0) { | ||
@@ -7,0 +17,0 @@ apiUrl = apiUrl + '&hash=' + crypto.createHash('md5').update(options['url'] + secretPhrase).digest("hex"); |
{ | ||
"name": "screenshotmachine", | ||
"version": "1.1.1", | ||
"description": "Capture website screenshots using ScreenshotMachine - online website screenshot generator and API", | ||
"version": "2.0.0", | ||
"description": "Captures website screenshot and converts website to PDF using Screenshot machine - online website screenshot generator and website to PDF converter", | ||
"main": "index.js", | ||
"keywords": [ | ||
"screenshotmachine", | ||
"screenshots", | ||
@@ -16,5 +15,8 @@ "screenshot", | ||
"html", | ||
"image", | ||
"browser", | ||
"capture" | ||
"capture", | ||
"pdf", | ||
"screen capture", | ||
"pdf generation", | ||
"html-to-pdf", | ||
"url-to-pdf" | ||
], | ||
@@ -21,0 +23,0 @@ "author": "Marek Knaze", |
# screenshotmachine-nodejs | ||
Captures website screenshot and converts website to PDF using Screenshot machine - online website screenshot generator and website to PDF converter | ||
This demo shows how to call online screenshot machine API using Node.js - JavaScript run-time environment. | ||
## Installation | ||
@@ -22,3 +21,4 @@ | ||
Set other options to fulfill your needs: | ||
## Website screenshot API | ||
Set additional options to fulfill your needs: | ||
@@ -29,3 +29,3 @@ ```javascript | ||
url : 'https://www.google.com', | ||
// all next parameters are optional, see our API guide for more details | ||
// all next parameters are optional, see our website screenshot API doc for more details | ||
dimension : '1366xfull', // or "1366xfull" for full length screenshot | ||
@@ -39,3 +39,3 @@ device : 'desktop', | ||
``` | ||
More info about options can be found in our [API doc](https://www.screenshotmachine.com/api.php). | ||
More info about options can be found in our [Website screenshot API](https://www.screenshotmachine.com/website-screenshot-api.php). | ||
@@ -53,3 +53,3 @@ Sample code | ||
url : 'https://www.google.com', | ||
// all next parameters are optional, see our API guide for more details | ||
// all next parameters are optional, see our website screenshot API guide for more details | ||
dimension : '1366xfull', // or "1366xfull" for full length screenshot | ||
@@ -63,6 +63,6 @@ device : 'desktop', | ||
var apiUrl = screenshotmachine.generateApiUrl(customerKey, secretPhrase, options); | ||
var apiUrl = screenshotmachine.generateScreenshotApiUrl(customerKey, secretPhrase, options); | ||
//put link to your html code | ||
console.log('<img src="' + apiUrl + '">'); | ||
console.log('<img src="' + apiUrl + '">'); | ||
``` | ||
@@ -81,3 +81,3 @@ Generated ```apiUrl``` link can be placed in ```<img>``` tag or used in your business logic later. | ||
url : 'https://www.google.com', | ||
// all next parameters are optional, see our API guide for more details | ||
// all next parameters are optional, see our website screenshot API guide for more details | ||
dimension : '1366xfull', // or "1366xfull" for full length screenshot | ||
@@ -91,3 +91,3 @@ device : 'desktop', | ||
var apiUrl = screenshotmachine.generateApiUrl(customerKey, secretPhrase, options); | ||
var apiUrl = screenshotmachine.generateScreenshotApiUrl(customerKey, secretPhrase, options); | ||
@@ -104,4 +104,51 @@ //save screenshot as an image | ||
## Website to PDF API | ||
Set the PDF options: | ||
```javascript | ||
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](https://www.screenshotmachine.com/website-to-pdf-api.php). | ||
#### Sample code | ||
```javascript | ||
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) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9171
6
67
146
3