mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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:
10
lib/Page.js
10
lib/Page.js
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user