Reputation: 1167
I tried to set the page size of PDF and make it to be landscape but fail. What should I change to make it effective?
I tried to add page.setViewport & isLandscape lots of time but still not making it effective.
browser = await puppeteer.launch({
executablePath: '/usr/bin/chromium-browser',
args: ['--no-sandbox', '--enable-font-antialiasing', '--font-render-hinting=medium'], //, '--window-size=1070x1514', '--disable-dev-shm-usage', '--disable-gpu', '--disable-software-rasterizer'
timeout: LOAD_TIMEOUT,
headless: true
,isLandscape: true
});
page = await browser.newPage();
await page.setViewport({
width: 1080,
height: 1600,
deviceScaleFactor: 1,
isLandscape: true
});
// local file
await page.goto(`file:///${ __dirname}/www/index.html`, {
waitUntil: 'domcontentloaded',
timeout: LOAD_TIMEOUT
});
await page.waitForFunction(() => !!(window.Ext && Ext.isReady && window.App && App.app), {
polling: LOAD_POLLING,
timeout: LOAD_TIMEOUT
});
await page.setViewport({
width: 1080,
height: 1600,
deviceScaleFactor: 1,
isLandscape: true
});
await page.evaluate(
App.pdf.Builder.create({
...
});
);
await page.waitForFunction(() => App.pdf.Builder.ready || App.pdf.Builder.error, {
polling: LOAD_POLLING,
timeout: PAGEBUILD_TIMEOUT
});
await page.pdf({
path: filePath,
format: 'A4',
margin: {
top: '0px',
right: '0px',
bottom: '0px',
left: '0px'
},
printBackground: true // required for photos otherwise blank
,scale: 0.5
});
I tried to add width: '1920px', height: '1080px'
in page.pdf()
but failed also. (only could make it to be landscape if set in page.pdf()
)
Upvotes: 1
Views: 6457
Reputation: 16856
According to the docs you also need to tell page.pdf
method that you'd like a landscape PDF:
await page.pdf({
landscape: true, // <-- must be set to true to get a landscape PDF
path: filePath,
format: 'A4',
margin: {
top: '0px',
right: '0px',
bottom: '0px',
left: '0px'
},
printBackground: true // required for photos otherwise blank
,scale: 0.5
});
Upvotes: 4