Compare commits

..

6 Commits

Author SHA1 Message Date
5c0b8c4df0 1.0.13 2019-06-03 13:02:01 +02:00
8da88be5e8 fix(core): update 2019-06-03 13:02:01 +02:00
4f0164965c 1.0.12 2019-06-03 13:00:06 +02:00
63f4321b04 fix(core): update 2019-06-03 13:00:06 +02:00
e4287e9943 1.0.11 2019-06-03 10:51:16 +02:00
337c299a5e fix(core): update 2019-06-03 10:51:15 +02:00
5 changed files with 26 additions and 15 deletions

2
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartpdf",
"version": "1.0.10",
"version": "1.0.13",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartpdf",
"version": "1.0.10",
"version": "1.0.13",
"private": false,
"description": "create pdfs on the fly",
"main": "dist/index.js",

1
ts/interfaces/index.ts Normal file
View File

@ -0,0 +1 @@
export * from './interface.pdfresult';

View File

@ -0,0 +1,5 @@
export interface IPdfResult {
name: string,
id: string,
buffer: Buffer;
}

View File

@ -5,26 +5,28 @@ import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
declare const document;
export interface IPdfResult {
name: string,
id: string,
buffer: Buffer;
}
import { IPdfResult } from './interfaces';
export class SmartPdf {
htmlServerInstance: Server;
serverPort: number;
headlessBrowser: plugins.puppeteer.Browser;
externalBrowser: boolean = false;
private _readyDeferred: plugins.smartpromise.Deferred<void>;
private _candidates: { [key: string]: PdfCandidate } = {};
constructor() {
constructor(headlessBrowserArg?) {
this.headlessBrowser = headlessBrowserArg
this._readyDeferred = new plugins.smartpromise.Deferred();
}
async start() {
// setup puppeteer
if (!this.headlessBrowser) {
this.headlessBrowser = await plugins.puppeteer.launch();
} else {
this.externalBrowser = true;
}
// setup server
const app = plugins.express();
@ -46,7 +48,11 @@ export class SmartPdf {
this.htmlServerInstance.close(() => {
done.resolve();
});
if (!this.externalBrowser) {
await this.headlessBrowser.close();
}
await done.promise;
}
@ -80,7 +86,7 @@ export class SmartPdf {
id: pdfCandidate.pdfId,
name: `${pdfCandidate.pdfId}.js`,
buffer: pdfBuffer
}
};
}
async getPdfForWebsite(websiteUrl: string): Promise<IPdfResult> {
@ -99,7 +105,7 @@ export class SmartPdf {
id: pdfId,
name: `${pdfId}.js`,
buffer: pdfBuffer
}
};
}
async getFullWebsiteAsSinglePdf(websiteUrl: string) {
@ -107,8 +113,7 @@ export class SmartPdf {
page.emulateMedia('screen');
const response = await page.goto(websiteUrl, { waitUntil: 'networkidle2' });
const pdfId = plugins.smartunique.shortId();
const {documentHeight, documentWidth} = await page.evaluate(() => {
const { documentHeight, documentWidth } = await page.evaluate(() => {
return {
documentHeight: document.height,
documentWidth: document.width
@ -126,6 +131,6 @@ export class SmartPdf {
id: pdfId,
name: `${pdfId}.js`,
buffer: pdfBuffer
}
};
}
}