Rename Page.printToPDF into page.pdf

This patch:
- renames Page.printToPDF into page.pdf
- adds a 'path' option to the page.pdf options instead of a separate
  `filePath` parameter
- improves on the documentation for the `page.pdf`

References #39.
This commit is contained in:
Andrey Lushnikov
2017-07-17 02:06:52 -07:00
parent 3b5dbe2308
commit b2d2bf822a
5 changed files with 58 additions and 25 deletions

View File

@@ -422,9 +422,9 @@ class Page extends EventEmitter {
/**
* @param {string} filePath
* @param {!Object=} options
* @return {!Promise}
* @return {!Promise<!Buffer>}
*/
async printToPDF(filePath, options) {
async pdf(options) {
options = options || {};
let scale = options.scale || 1;
@@ -465,7 +465,9 @@ class Page extends EventEmitter {
pageRanges: pageRanges
});
let buffer = new Buffer(result.data, 'base64');
fs.writeFileSync(filePath, buffer);
if (options.path)
fs.writeFileSync(options.path, buffer);
return buffer;
}
/**
@@ -652,7 +654,7 @@ function convertPrintParameterToInches(parameter) {
console.assert(!isNaN(value), 'Failed to parse parameter value: ' + text);
pixels = value * unitToPixels[unit];
} else {
throw new Error('printToPDF Cannot handle parameter type: ' + (typeof parameter));
throw new Error('page.pdf() Cannot handle parameter type: ' + (typeof parameter));
}
return pixels / 96;
}