fix(core): update

This commit is contained in:
Philipp Kunz 2019-05-29 00:27:43 +02:00
parent 20847362a1
commit e981d61a54
10 changed files with 578 additions and 343 deletions

Binary file not shown.

Binary file not shown.

BIN
assets/pdfdir/r2nfLxJWf.pdf Normal file

Binary file not shown.

865
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -13,21 +13,21 @@
"build": "(tsbuild)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.8",
"@gitzone/tsrun": "^1.2.5",
"@gitzone/tstest": "^1.0.20",
"@gitzone/tsbuild": "^2.1.11",
"@gitzone/tsrun": "^1.2.6",
"@gitzone/tstest": "^1.0.24",
"@pushrocks/tapbundle": "^3.0.9",
"@types/node": "^11.13.2"
"@types/node": "^12.0.3"
},
"dependencies": {
"@pushrocks/smartfile": "^7.0.2",
"@pushrocks/smartnetwork": "^1.1.0",
"@pushrocks/smartnetwork": "^1.1.6",
"@pushrocks/smartpromise": "^3.0.2",
"@pushrocks/smartunique": "^3.0.1",
"@types/express": "^4.16.1",
"@types/puppeteer": "^1.12.3",
"express": "^4.16.4",
"puppeteer": "^1.14.0"
"@types/puppeteer": "^1.12.4",
"express": "^4.17.1",
"puppeteer": "^1.17.0"
},
"files": [
"ts/*",

View File

@ -12,10 +12,14 @@ tap.test('should create a pdf from html string', async () => {
await testSmartPdf.getPdfForHtmlString('hi');
});
tap.test('should create a pdf from website', async () => {
tap.test('should create a pdf from website as A4', async () => {
await testSmartPdf.getPdfForWebsite('https://maintainedby.lossless.com');
});
tap.test('should create a pdf from website as single page PDF', async () => {
await testSmartPdf.getFullWebsiteAsSinglePdf('https://maintainedby.lossless.com');
});
tap.test('should be able to close properly', async () => {
await testSmartPdf.close();
});

View File

@ -3,6 +3,8 @@ import * as paths from './smartpdf.paths';
import { Server } from 'http';
import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
declare const document;
export class SmartPdf {
htmlServerInstance: Server;
serverPort: number;
@ -85,4 +87,26 @@ export class SmartPdf {
});
await page.close();
}
async getFullWebsiteAsSinglePdf(websiteUrl: string) {
const page = await this.headlessBrowser.newPage();
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
};
});
await page.pdf({
path: plugins.path.join(paths.pdfDir, `${pdfId}.pdf`),
height: documentWidth,
width: documentWidth,
printBackground: true,
displayHeaderFooter: false,
preferCSSPageSize: true
});
await page.close();
}
}

View File

@ -13,7 +13,7 @@ import * as smartunique from '@pushrocks/smartunique';
export { smartfile, smartpromise, smartunique, smartnetwork };
// thirdparty
import * as express from 'express';
import * as puppeteer from 'puppeteer';
import express from 'express';
import puppeteer from 'puppeteer';
export { express, puppeteer };