Compare commits

...

11 Commits

Author SHA1 Message Date
94dd576d3b 2.0.0 2019-11-19 15:53:14 +00:00
9c19b4a3e4 BREAKING CHANGE(API): now clearly naming PDF Results what they are. 2019-11-19 15:53:14 +00:00
1155656c2b 1.0.29 2019-11-16 00:50:12 +01:00
5cf23c1134 fix(core): update 2019-11-16 00:50:11 +01:00
67e9fdd10a 1.0.28 2019-11-15 20:00:25 +01:00
b0e388c50d 1.0.27 2019-11-15 19:59:57 +01:00
f37c9d8375 fix(core): update 2019-11-15 19:59:57 +01:00
18c8ef9606 1.0.26 2019-11-12 15:45:26 +01:00
6766a3d0dc fix(core): update 2019-11-12 15:45:26 +01:00
d16f447048 1.0.25 2019-11-12 15:41:58 +01:00
37c752c2ae fix(core): update 2019-11-12 15:41:58 +01:00
4 changed files with 58 additions and 51 deletions

73
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartpdf",
"version": "1.0.24",
"version": "2.0.0",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -140,11 +140,21 @@
"version": "2.0.6",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.6.tgz",
"integrity": "sha512-4wUnzWNhRPODpaaL5GuRaje/C5dg+TMhBxmr57PKc2fqYpy6azWJwonf/s5xpcbJLCPJRbj1x8M5MqgCFq2uvg==",
"dev": true,
"requires": {
"@pushrocks/smartpromise": "^3.0.6"
}
},
"@pushrocks/smartenv": {
"version": "4.0.8",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartenv/-/smartenv-4.0.8.tgz",
"integrity": "sha512-gKEL1/ogJwss2b/xjbOen5s+9geT5XUvNXuD1qUpc1t5P9w0BaXXuLw7vz1pVRxb/NWtmPLRIdVbAxL1OmmwCg==",
"requires": {
"@pushrocks/smartparam": "^1.0.4",
"@pushrocks/smartpromise": "^3.0.6",
"@types/node": "^12.12.7",
"is-wsl": "^2.1.1"
}
},
"@pushrocks/smartevent": {
"version": "2.0.3",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartevent/-/smartevent-2.0.3.tgz",
@ -256,7 +266,6 @@
"version": "1.0.4",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartparam/-/smartparam-1.0.4.tgz",
"integrity": "sha512-UAqhnTQGBaJRptTK3qTd47Yt2ZTrAWByteow4auSNZD+k0xrpY9mTPPgKh0IwsURe0cZhj7zYNpGiekhKkL4rA==",
"dev": true,
"requires": {
"@pushrocks/smartpromise": "^2.0.5",
"is-promise": "^2.1.0",
@ -266,8 +275,7 @@
"@pushrocks/smartpromise": {
"version": "2.0.5",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz",
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==",
"dev": true
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g=="
}
}
},
@ -282,12 +290,14 @@
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
},
"@pushrocks/smartpuppeteer": {
"version": "1.0.5",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpuppeteer/-/smartpuppeteer-1.0.5.tgz",
"integrity": "sha512-7iD2mxQHXG5/6PwZY2wU6GQjNXy9dR5cLP/nvfjxXaelX/x3N1yagjPAuMYxuIqiTtVfrHC4Ehq+gnTZ4mSPow==",
"version": "1.0.11",
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpuppeteer/-/smartpuppeteer-1.0.11.tgz",
"integrity": "sha512-a38EUpOigY5PYFFgl/N6tkPdv4GYvU5zRAb+adwZts1uNe15UIKpC7upkA2QykuYU0ueMgc0a+JMB1qeJsA7HQ==",
"requires": {
"@types/puppeteer": "^1.12.4",
"puppeteer": "^1.17.0"
"@pushrocks/smartdelay": "^2.0.6",
"@pushrocks/smartenv": "^4.0.8",
"@types/puppeteer": "^1.20.2",
"puppeteer": "^2.0.0"
}
},
"@pushrocks/smartrequest": {
@ -508,9 +518,9 @@
"dev": true
},
"@types/node": {
"version": "12.12.7",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.12.7.tgz",
"integrity": "sha512-E6Zn0rffhgd130zbCbAr/JdXfXkoOUFAKNs/rF8qnafSJ8KYaA/j3oz7dcwal+lYjLA7xvdd5J4wdYpCTlP8+w=="
"version": "12.12.8",
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.12.8.tgz",
"integrity": "sha512-XLla8N+iyfjvsa0KKV+BP/iGSoTmwxsu5Ci5sM33z9TjohF72DEz95iNvD6pPmemvbQgxAv/909G73gUn8QR7w=="
},
"@types/portscanner": {
"version": "2.1.0",
@ -1501,8 +1511,7 @@
"is-promise": {
"version": "2.1.0",
"resolved": "https://verdaccio.lossless.one/is-promise/-/is-promise-2.1.0.tgz",
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
"dev": true
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
},
"is-regex": {
"version": "1.0.4",
@ -1525,6 +1534,11 @@
"has-symbols": "^1.0.0"
}
},
"is-wsl": {
"version": "2.1.1",
"resolved": "https://verdaccio.lossless.one/is-wsl/-/is-wsl-2.1.1.tgz",
"integrity": "sha512-umZHcSrwlDHo2TGMXv0DZ8dIUGunZ2Iv68YZnrmCiBPkZ4aaOhtv7pXJKeki9k3qJ3RJr0cDyitcl5wEH3AYog=="
},
"isarray": {
"version": "1.0.0",
"resolved": "https://verdaccio.lossless.one/isarray/-/isarray-1.0.0.tgz",
@ -2074,39 +2088,18 @@
}
},
"puppeteer": {
"version": "1.20.0",
"resolved": "https://verdaccio.lossless.one/puppeteer/-/puppeteer-1.20.0.tgz",
"integrity": "sha512-bt48RDBy2eIwZPrkgbcwHtb51mj2nKvHOPMaSH2IsWiv7lOG9k9zhaRzpDZafrk05ajMc3cu+lSQYYOfH2DkVQ==",
"version": "2.0.0",
"resolved": "https://verdaccio.lossless.one/puppeteer/-/puppeteer-2.0.0.tgz",
"integrity": "sha512-t3MmTWzQxPRP71teU6l0jX47PHXlc4Z52sQv4LJQSZLq1ttkKS2yGM3gaI57uQwZkNaoGd0+HPPMELZkcyhlqA==",
"requires": {
"debug": "^4.1.0",
"extract-zip": "^1.6.6",
"https-proxy-agent": "^2.2.1",
"https-proxy-agent": "^3.0.0",
"mime": "^2.0.3",
"progress": "^2.0.1",
"proxy-from-env": "^1.0.0",
"rimraf": "^2.6.1",
"ws": "^6.1.0"
},
"dependencies": {
"https-proxy-agent": {
"version": "2.2.4",
"resolved": "https://verdaccio.lossless.one/https-proxy-agent/-/https-proxy-agent-2.2.4.tgz",
"integrity": "sha512-OmvfoQ53WLjtA9HeYP9RNrWMJzzAz1JGaSFr1nijg0PVR1JaD/xbJq1mdEIIlxGpXp9eSe/O2LgU9DJmTPd0Eg==",
"requires": {
"agent-base": "^4.3.0",
"debug": "^3.1.0"
},
"dependencies": {
"debug": {
"version": "3.2.6",
"resolved": "https://verdaccio.lossless.one/debug/-/debug-3.2.6.tgz",
"integrity": "sha512-mel+jf7nrtEl5Pn1Qx46zARXKDpBbvzezse7p7LqINmdoIk8PYP5SySaxEmYv6TZ0JyEKA1hsCId6DIhgITtWQ==",
"requires": {
"ms": "^2.1.1"
}
}
}
}
}
},
"qs": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartpdf",
"version": "1.0.24",
"version": "2.0.0",
"private": false,
"description": "create pdfs on the fly",
"main": "dist/index.js",
@ -17,7 +17,7 @@
"@gitzone/tsrun": "^1.2.8",
"@gitzone/tstest": "^1.0.28",
"@pushrocks/tapbundle": "^3.0.13",
"@types/node": "^12.12.7",
"@types/node": "^12.12.8",
"tslint": "^6.0.0-beta0",
"tslint-config-prettier": "^1.18.0"
},
@ -25,7 +25,7 @@
"@pushrocks/smartfile": "^7.0.6",
"@pushrocks/smartnetwork": "^1.1.14",
"@pushrocks/smartpromise": "^3.0.6",
"@pushrocks/smartpuppeteer": "^1.0.5",
"@pushrocks/smartpuppeteer": "^1.0.11",
"@pushrocks/smartunique": "^3.0.1",
"@types/express": "^4.17.2",
"express": "^4.17.1"

View File

@ -13,15 +13,15 @@ tap.test('should start the instance', async () => {
});
tap.test('should create a pdf from html string', async () => {
await testSmartPdf.getPdfForHtmlString('hi');
await testSmartPdf.getPdfResultForHtmlString('hi');
});
tap.test('should create a pdf from website as A4', async () => {
await testSmartPdf.getPdfForWebsite('https://maintainedby.lossless.com');
await testSmartPdf.getPdfResultForWebsite('https://www.wikipedia.org');
});
tap.test('should create a pdf from website as single page PDF', async () => {
await testSmartPdf.getFullWebsiteAsSinglePdf('https://maintainedby.lossless.com');
await testSmartPdf.getFullWebsiteAsSinglePdf('https://www.wikipedia.org');
});
tap.test('should create a valid PDFResult', async () => {

View File

@ -26,7 +26,9 @@ export class SmartPdf {
if (this.headlessBrowser) {
this.externalBrowserBool = true;
} else {
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance({
forceNoSandbox: true
});
}
// setup server
@ -61,7 +63,7 @@ export class SmartPdf {
/**
* returns a pdf for a given html string;
*/
async getPdfForHtmlString(htmlStringArg: string): Promise<interfaces.IPdfResult> {
async getPdfResultForHtmlString(htmlStringArg: string): Promise<interfaces.IPdfResult> {
await this._readyDeferred.promise;
const pdfCandidate = new PdfCandidate(htmlStringArg);
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
@ -78,7 +80,10 @@ export class SmartPdf {
}
const pdfBuffer = await page.pdf({
format: 'A4'
format: 'A4',
printBackground: true,
displayHeaderFooter: false,
preferCSSPageSize: true
});
await page.close();
delete this._candidates[pdfCandidate.pdfId];
@ -91,13 +96,21 @@ export class SmartPdf {
};
}
async getPdfForWebsite(websiteUrl: string): Promise<interfaces.IPdfResult> {
async getPdfResultForWebsite(websiteUrl: string): Promise<interfaces.IPdfResult> {
const page = await this.headlessBrowser.newPage();
page.emulateMedia('screen');
await page.emulateMedia('screen');
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
const pdfId = plugins.smartunique.shortId();
const { documentHeight, documentWidth } = await page.evaluate(() => {
return {
documentHeight: document.height,
documentWidth: document.width
};
});
const pdfBuffer = await page.pdf({
format: 'A4',
height: documentWidth,
width: documentWidth,
printBackground: true,
displayHeaderFooter: false,
preferCSSPageSize: true
@ -122,6 +135,7 @@ export class SmartPdf {
};
});
const pdfBuffer = await page.pdf({
format: 'A4',
height: documentWidth,
width: documentWidth,
printBackground: true,