fixes pdf export of images

pr169
bckmnn 2021-02-20 17:04:58 +01:00
parent 5c753cb82a
commit 6bd7130597
2 changed files with 10 additions and 22 deletions

View File

@ -21,18 +21,6 @@ module.exports = {
console.log("[space-screenshot] url: "+space_url);
console.log("[space-screenshot] export_path: "+export_path);
var on_success_called = false;
var on_exit = function(exit_code) {
if (exit_code>0) {
console.error(exit_code);
console.error("puppeteer abnormal exit for url "+space_url);
if (!on_success_called && on_error) {
on_error();
}
}
};
(async () => {
let browser;
let page;
@ -47,19 +35,20 @@ module.exports = {
page.setDefaultTimeout(timeout);
await page.setJavaScriptEnabled(false);
console.log("page created, opening ",space_url);
await page.goto(space_url, {waitUntil: 'networkidle0'});
await page.goto(space_url, {waitUntil: 'networkidle2'});
await page.emulateMedia('screen');
if (type=="pdf") {
await page.pdf({path: export_path, width: space.width+'px', height: space.height+'px' });
await page.pdf({path: export_path, printBackground: true, width: space.width+'px', height: space.height+'px' });
}else{
await page.screenshot({path: export_path});
await page.screenshot({path: export_path, printBackground: true});
}
await browser.close();
on_success(export_path);
} catch (error) {
console.error(error);
console.error("[space-screenshot] puppeteer abnormal exit for url "+space_url);
on_error();
}

View File

@ -39,16 +39,15 @@ function website_to_png(url,on_success,on_error) {
page.setDefaultTimeout(timeout);
await page.setJavaScriptEnabled(false);
console.log("page created, opening ",url);
await page.goto(url, {waitUntil: 'networkidle0'});
await page.screenshot({path: export_path});
await page.goto(url, {waitUntil: 'networkidle2'});
await page.emulateMedia('screen');
await page.screenshot({path: export_path, printBackground: true});
await browser.close();
on_success(export_path);
} catch (error) {
console.error(error);
console.log("[puppeteer-webgrabber] abnormal exit for url "+url);
console.log("[webgrabber] puppeteer abnormal exit for url "+url);
on_error();
}