mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
Page.pdf should accept case-insensetive page format (#211)
This commit is contained in:
parent
00196e6cdc
commit
7888a37a3d
22
lib/Page.js
22
lib/Page.js
@ -470,7 +470,7 @@ class Page extends EventEmitter {
|
|||||||
let paperWidth = 8.5;
|
let paperWidth = 8.5;
|
||||||
let paperHeight = 11;
|
let paperHeight = 11;
|
||||||
if (options.format) {
|
if (options.format) {
|
||||||
let format = Page.PaperFormats[options.format];
|
let format = Page.PaperFormats[options.format.toLowerCase()];
|
||||||
console.assert(format, 'Unknown paper format: ' + options.format);
|
console.assert(format, 'Unknown paper format: ' + options.format);
|
||||||
paperWidth = format.width;
|
paperWidth = format.width;
|
||||||
paperHeight = format.height;
|
paperHeight = format.height;
|
||||||
@ -627,16 +627,16 @@ class Page extends EventEmitter {
|
|||||||
|
|
||||||
/** @enum {string} */
|
/** @enum {string} */
|
||||||
Page.PaperFormats = {
|
Page.PaperFormats = {
|
||||||
Letter: {width: 8.5, height: 11},
|
letter: {width: 8.5, height: 11},
|
||||||
Legal: {width: 8.5, height: 14},
|
legal: {width: 8.5, height: 14},
|
||||||
Tabloid: {width: 11, height: 17},
|
tabloid: {width: 11, height: 17},
|
||||||
Ledger: {width: 17, height: 11},
|
ledger: {width: 17, height: 11},
|
||||||
A0: {width: 33.1, height: 46.8 },
|
a0: {width: 33.1, height: 46.8 },
|
||||||
A1: {width: 23.4, height: 33.1 },
|
a1: {width: 23.4, height: 33.1 },
|
||||||
A2: {width: 16.5, height: 23.4 },
|
a2: {width: 16.5, height: 23.4 },
|
||||||
A3: {width: 11.7, height: 16.5 },
|
a3: {width: 11.7, height: 16.5 },
|
||||||
A4: {width: 8.27, height: 11.7 },
|
a4: {width: 8.27, height: 11.7 },
|
||||||
A5: {width: 5.83, height: 8.27 },
|
a5: {width: 5.83, height: 8.27 },
|
||||||
};
|
};
|
||||||
|
|
||||||
let unitToPixels = {
|
let unitToPixels = {
|
||||||
|
@ -1407,7 +1407,7 @@ describe('Page', function() {
|
|||||||
}));
|
}));
|
||||||
it('should support setting custom format', SX(async function() {
|
it('should support setting custom format', SX(async function() {
|
||||||
let pages = await getPDFPages(await page.pdf({
|
let pages = await getPDFPages(await page.pdf({
|
||||||
format: 'A4'
|
format: 'a4'
|
||||||
}));
|
}));
|
||||||
expect(pages.length).toBe(1);
|
expect(pages.length).toBe(1);
|
||||||
expect(pages[0].width).toBeCloseTo(8.27, 1);
|
expect(pages[0].width).toBeCloseTo(8.27, 1);
|
||||||
|
Loading…
Reference in New Issue
Block a user