Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
94dd576d3b | |||
9c19b4a3e4 | |||
1155656c2b | |||
5cf23c1134 | |||
67e9fdd10a | |||
b0e388c50d | |||
f37c9d8375 | |||
18c8ef9606 | |||
6766a3d0dc | |||
d16f447048 | |||
37c752c2ae |
73
package-lock.json
generated
73
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "1.0.24",
|
"version": "2.0.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@ -140,11 +140,21 @@
|
|||||||
"version": "2.0.6",
|
"version": "2.0.6",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.6.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartdelay/-/smartdelay-2.0.6.tgz",
|
||||||
"integrity": "sha512-4wUnzWNhRPODpaaL5GuRaje/C5dg+TMhBxmr57PKc2fqYpy6azWJwonf/s5xpcbJLCPJRbj1x8M5MqgCFq2uvg==",
|
"integrity": "sha512-4wUnzWNhRPODpaaL5GuRaje/C5dg+TMhBxmr57PKc2fqYpy6azWJwonf/s5xpcbJLCPJRbj1x8M5MqgCFq2uvg==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartpromise": "^3.0.6"
|
"@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": {
|
"@pushrocks/smartevent": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartevent/-/smartevent-2.0.3.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartevent/-/smartevent-2.0.3.tgz",
|
||||||
@ -256,7 +266,6 @@
|
|||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartparam/-/smartparam-1.0.4.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartparam/-/smartparam-1.0.4.tgz",
|
||||||
"integrity": "sha512-UAqhnTQGBaJRptTK3qTd47Yt2ZTrAWByteow4auSNZD+k0xrpY9mTPPgKh0IwsURe0cZhj7zYNpGiekhKkL4rA==",
|
"integrity": "sha512-UAqhnTQGBaJRptTK3qTd47Yt2ZTrAWByteow4auSNZD+k0xrpY9mTPPgKh0IwsURe0cZhj7zYNpGiekhKkL4rA==",
|
||||||
"dev": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"@pushrocks/smartpromise": "^2.0.5",
|
"@pushrocks/smartpromise": "^2.0.5",
|
||||||
"is-promise": "^2.1.0",
|
"is-promise": "^2.1.0",
|
||||||
@ -266,8 +275,7 @@
|
|||||||
"@pushrocks/smartpromise": {
|
"@pushrocks/smartpromise": {
|
||||||
"version": "2.0.5",
|
"version": "2.0.5",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpromise/-/smartpromise-2.0.5.tgz",
|
||||||
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g==",
|
"integrity": "sha512-9j/chLtIiNkR0MDw7Mpxg9slxAVvAQwUZuiaPYX5KpHdKxQaHLI1VZ8IN0vPhwlfgNO4i4vGXV0wB8BvSDj03g=="
|
||||||
"dev": true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -282,12 +290,14 @@
|
|||||||
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
|
"integrity": "sha512-vlQlBGNVIjfClgnsfgQBU6GIKcskYSFzEcKLt18ngPzPEcjKklXcxaqzLXpnoxR+KBh30QPE8255ncYHXuPPOg=="
|
||||||
},
|
},
|
||||||
"@pushrocks/smartpuppeteer": {
|
"@pushrocks/smartpuppeteer": {
|
||||||
"version": "1.0.5",
|
"version": "1.0.11",
|
||||||
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpuppeteer/-/smartpuppeteer-1.0.5.tgz",
|
"resolved": "https://verdaccio.lossless.one/@pushrocks%2fsmartpuppeteer/-/smartpuppeteer-1.0.11.tgz",
|
||||||
"integrity": "sha512-7iD2mxQHXG5/6PwZY2wU6GQjNXy9dR5cLP/nvfjxXaelX/x3N1yagjPAuMYxuIqiTtVfrHC4Ehq+gnTZ4mSPow==",
|
"integrity": "sha512-a38EUpOigY5PYFFgl/N6tkPdv4GYvU5zRAb+adwZts1uNe15UIKpC7upkA2QykuYU0ueMgc0a+JMB1qeJsA7HQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@types/puppeteer": "^1.12.4",
|
"@pushrocks/smartdelay": "^2.0.6",
|
||||||
"puppeteer": "^1.17.0"
|
"@pushrocks/smartenv": "^4.0.8",
|
||||||
|
"@types/puppeteer": "^1.20.2",
|
||||||
|
"puppeteer": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@pushrocks/smartrequest": {
|
"@pushrocks/smartrequest": {
|
||||||
@ -508,9 +518,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "12.12.7",
|
"version": "12.12.8",
|
||||||
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.12.7.tgz",
|
"resolved": "https://verdaccio.lossless.one/@types%2fnode/-/node-12.12.8.tgz",
|
||||||
"integrity": "sha512-E6Zn0rffhgd130zbCbAr/JdXfXkoOUFAKNs/rF8qnafSJ8KYaA/j3oz7dcwal+lYjLA7xvdd5J4wdYpCTlP8+w=="
|
"integrity": "sha512-XLla8N+iyfjvsa0KKV+BP/iGSoTmwxsu5Ci5sM33z9TjohF72DEz95iNvD6pPmemvbQgxAv/909G73gUn8QR7w=="
|
||||||
},
|
},
|
||||||
"@types/portscanner": {
|
"@types/portscanner": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
@ -1501,8 +1511,7 @@
|
|||||||
"is-promise": {
|
"is-promise": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/is-promise/-/is-promise-2.1.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/is-promise/-/is-promise-2.1.0.tgz",
|
||||||
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o=",
|
"integrity": "sha1-eaKp7OfwlugPNtKy87wWwf9L8/o="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"is-regex": {
|
"is-regex": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.4",
|
||||||
@ -1525,6 +1534,11 @@
|
|||||||
"has-symbols": "^1.0.0"
|
"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": {
|
"isarray": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/isarray/-/isarray-1.0.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/isarray/-/isarray-1.0.0.tgz",
|
||||||
@ -2074,39 +2088,18 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"puppeteer": {
|
"puppeteer": {
|
||||||
"version": "1.20.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://verdaccio.lossless.one/puppeteer/-/puppeteer-1.20.0.tgz",
|
"resolved": "https://verdaccio.lossless.one/puppeteer/-/puppeteer-2.0.0.tgz",
|
||||||
"integrity": "sha512-bt48RDBy2eIwZPrkgbcwHtb51mj2nKvHOPMaSH2IsWiv7lOG9k9zhaRzpDZafrk05ajMc3cu+lSQYYOfH2DkVQ==",
|
"integrity": "sha512-t3MmTWzQxPRP71teU6l0jX47PHXlc4Z52sQv4LJQSZLq1ttkKS2yGM3gaI57uQwZkNaoGd0+HPPMELZkcyhlqA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"debug": "^4.1.0",
|
"debug": "^4.1.0",
|
||||||
"extract-zip": "^1.6.6",
|
"extract-zip": "^1.6.6",
|
||||||
"https-proxy-agent": "^2.2.1",
|
"https-proxy-agent": "^3.0.0",
|
||||||
"mime": "^2.0.3",
|
"mime": "^2.0.3",
|
||||||
"progress": "^2.0.1",
|
"progress": "^2.0.1",
|
||||||
"proxy-from-env": "^1.0.0",
|
"proxy-from-env": "^1.0.0",
|
||||||
"rimraf": "^2.6.1",
|
"rimraf": "^2.6.1",
|
||||||
"ws": "^6.1.0"
|
"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": {
|
"qs": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "1.0.24",
|
"version": "2.0.0",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "create pdfs on the fly",
|
"description": "create pdfs on the fly",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
@ -17,7 +17,7 @@
|
|||||||
"@gitzone/tsrun": "^1.2.8",
|
"@gitzone/tsrun": "^1.2.8",
|
||||||
"@gitzone/tstest": "^1.0.28",
|
"@gitzone/tstest": "^1.0.28",
|
||||||
"@pushrocks/tapbundle": "^3.0.13",
|
"@pushrocks/tapbundle": "^3.0.13",
|
||||||
"@types/node": "^12.12.7",
|
"@types/node": "^12.12.8",
|
||||||
"tslint": "^6.0.0-beta0",
|
"tslint": "^6.0.0-beta0",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
@ -25,7 +25,7 @@
|
|||||||
"@pushrocks/smartfile": "^7.0.6",
|
"@pushrocks/smartfile": "^7.0.6",
|
||||||
"@pushrocks/smartnetwork": "^1.1.14",
|
"@pushrocks/smartnetwork": "^1.1.14",
|
||||||
"@pushrocks/smartpromise": "^3.0.6",
|
"@pushrocks/smartpromise": "^3.0.6",
|
||||||
"@pushrocks/smartpuppeteer": "^1.0.5",
|
"@pushrocks/smartpuppeteer": "^1.0.11",
|
||||||
"@pushrocks/smartunique": "^3.0.1",
|
"@pushrocks/smartunique": "^3.0.1",
|
||||||
"@types/express": "^4.17.2",
|
"@types/express": "^4.17.2",
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1"
|
||||||
|
@ -13,15 +13,15 @@ tap.test('should start the instance', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a pdf from html string', 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 () => {
|
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 () => {
|
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 () => {
|
tap.test('should create a valid PDFResult', async () => {
|
||||||
|
@ -26,7 +26,9 @@ export class SmartPdf {
|
|||||||
if (this.headlessBrowser) {
|
if (this.headlessBrowser) {
|
||||||
this.externalBrowserBool = true;
|
this.externalBrowserBool = true;
|
||||||
} else {
|
} else {
|
||||||
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance();
|
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance({
|
||||||
|
forceNoSandbox: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// setup server
|
// setup server
|
||||||
@ -61,7 +63,7 @@ export class SmartPdf {
|
|||||||
/**
|
/**
|
||||||
* returns a pdf for a given html string;
|
* 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;
|
await this._readyDeferred.promise;
|
||||||
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
||||||
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
||||||
@ -78,7 +80,10 @@ export class SmartPdf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'A4'
|
format: 'A4',
|
||||||
|
printBackground: true,
|
||||||
|
displayHeaderFooter: false,
|
||||||
|
preferCSSPageSize: true
|
||||||
});
|
});
|
||||||
await page.close();
|
await page.close();
|
||||||
delete this._candidates[pdfCandidate.pdfId];
|
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();
|
const page = await this.headlessBrowser.newPage();
|
||||||
page.emulateMedia('screen');
|
await page.emulateMedia('screen');
|
||||||
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
|
||||||
const pdfId = plugins.smartunique.shortId();
|
const pdfId = plugins.smartunique.shortId();
|
||||||
|
const { documentHeight, documentWidth } = await page.evaluate(() => {
|
||||||
|
return {
|
||||||
|
documentHeight: document.height,
|
||||||
|
documentWidth: document.width
|
||||||
|
};
|
||||||
|
});
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'A4',
|
format: 'A4',
|
||||||
|
height: documentWidth,
|
||||||
|
width: documentWidth,
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
preferCSSPageSize: true
|
preferCSSPageSize: true
|
||||||
@ -122,6 +135,7 @@ export class SmartPdf {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
|
format: 'A4',
|
||||||
height: documentWidth,
|
height: documentWidth,
|
||||||
width: documentWidth,
|
width: documentWidth,
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
|
Reference in New Issue
Block a user