Compare commits

...

19 Commits

Author SHA1 Message Date
b8387458db 2.0.3 2021-03-05 15:16:23 +00:00
04aed2556b fix(core): update 2021-03-05 15:16:22 +00:00
4cde3a7fe0 2.0.2 2019-11-19 16:31:34 +00:00
466d6d47ba fix(ci): further speed up snyk step 2019-11-19 16:31:33 +00:00
fa99b7f068 2.0.1 2019-11-19 16:28:14 +00:00
3e865b6c92 fix(ci): update snyk step for faster testing 2019-11-19 16:28:13 +00:00
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
b088d26e6f 1.0.24 2019-11-12 14:41:04 +01:00
425f11a334 fix(core): update 2019-11-12 14:41:03 +01:00
5 changed files with 9286 additions and 865 deletions

View File

@ -25,11 +25,11 @@ mirror:
- notpriv - notpriv
snyk: snyk:
image: registry.gitlab.com/hosttoday/ht-docker-node:snyk
stage: security stage: security
script: script:
- npmci npm prepare - npmci npm prepare
- npmci command npm install -g snyk - npmci command npm ci --ignore-scripts
- npmci command npm install --ignore-scripts
- npmci command snyk test - npmci command snyk test
tags: tags:
- lossless - lossless

10073
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "@pushrocks/smartpdf", "name": "@pushrocks/smartpdf",
"version": "1.0.23", "version": "2.0.3",
"private": false, "private": false,
"description": "create pdfs on the fly", "description": "create pdfs on the fly",
"main": "dist/index.js", "main": "dist/index.js",
@ -13,19 +13,21 @@
"build": "(tsbuild)" "build": "(tsbuild)"
}, },
"devDependencies": { "devDependencies": {
"@gitzone/tsbuild": "^2.1.17", "@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.8", "@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.28", "@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.0.13", "@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^12.12.7" "@types/node": "^14.14.31",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
}, },
"dependencies": { "dependencies": {
"@pushrocks/smartfile": "^7.0.6", "@pushrocks/smartfile": "^8.0.8",
"@pushrocks/smartnetwork": "^1.1.14", "@pushrocks/smartnetwork": "^1.1.22",
"@pushrocks/smartpromise": "^3.0.6", "@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartpuppeteer": "^1.0.5", "@pushrocks/smartpuppeteer": "^1.0.21",
"@pushrocks/smartunique": "^3.0.1", "@pushrocks/smartunique": "^3.0.3",
"@types/express": "^4.17.2", "@types/express": "^4.17.11",
"express": "^4.17.1" "express": "^4.17.1"
}, },
"files": [ "files": [

View File

@ -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 () => {

View File

@ -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.emulateMediaType('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
@ -112,7 +125,7 @@ export class SmartPdf {
async getFullWebsiteAsSinglePdf(websiteUrl: string) { async getFullWebsiteAsSinglePdf(websiteUrl: string) {
const page = await this.headlessBrowser.newPage(); const page = await this.headlessBrowser.newPage();
page.emulateMedia('screen'); page.emulateMediaType('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(() => { const { documentHeight, documentWidth } = await page.evaluate(() => {
@ -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,