Skip to content
Snippets Groups Projects

Fix calculations for pages with bleeds set

Merged Boris Budini requested to merge master into master
1 file
+ 1
15
Compare changes
  • Side-by-side
  • Inline
+ 1
15
@@ -192,7 +192,7 @@ class Printer extends EventEmitter {
@@ -192,7 +192,7 @@ class Printer extends EventEmitter {
let settings = {
let settings = {
printBackground: true,
printBackground: true,
displayHeaderFooter: false,
displayHeaderFooter: false,
// preferCSSPageSize: options.width ? false : true, // does not currently work with bleeds: needs to be calculated from the document
preferCSSPageSize: options.width ? false : true,
width: options.width,
width: options.width,
height: options.height,
height: options.height,
orientation: options.orientation,
orientation: options.orientation,
@@ -204,20 +204,6 @@ class Printer extends EventEmitter {
@@ -204,20 +204,6 @@ class Printer extends EventEmitter {
}
}
}
}
if (!options.width) { // calculate paper size from the first page's dimensions
await page.exposeFunction('setWidthHeight', (width, height) => {
settings.width = `${width}mm`;
settings.height = `${height}mm`;
});
await page.evaluate(() => {
const rect = document.querySelector('.pagedjs_page').getBoundingClientRect();
setWidthHeight(
Math.round(CSS.px(rect.width).to('mm').value),
Math.round(CSS.px(rect.height).to('mm').value)
);
});
}
let pdf = await page.pdf(settings)
let pdf = await page.pdf(settings)
.catch((e) => {
.catch((e) => {
console.error(e);
console.error(e);