Compare commits

..

7 Commits

Author SHA1 Message Date
06b9385e97 1.0.8 2019-05-29 19:18:44 +02:00
94386b0e02 fix(core): update 2019-05-29 19:18:43 +02:00
36fea0b0f2 Merge branch 'master' of gitlab.com:pushrocks/smartpdf 2019-05-29 19:17:54 +02:00
437d56e54d 1.0.7 2019-05-29 19:17:39 +02:00
1537705cde fix(core): update 2019-05-29 19:17:39 +02:00
bb7cb4a6ab 1.0.7 2019-05-29 14:14:03 +02:00
bda43bf5e7 fix(core): update 2019-05-29 14:14:02 +02:00
7 changed files with 11 additions and 6 deletions

2
package-lock.json generated
View File

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

View File

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

View File

@ -8,6 +8,10 @@ tap.test('should create a valid instance of smartpdf', async () => {
expect(testSmartPdf).to.be.instanceof(smartpdf.SmartPdf); expect(testSmartPdf).to.be.instanceof(smartpdf.SmartPdf);
}); });
tap.test('should start the instance', async () => {
await testSmartPdf.start();
});
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.getPdfForHtmlString('hi');
}); });
@ -21,7 +25,7 @@ tap.test('should create a pdf from website as single page PDF', async () => {
}); });
tap.test('should be able to close properly', async () => { tap.test('should be able to close properly', async () => {
await testSmartPdf.close(); await testSmartPdf.stop();
}); });
tap.start(); tap.start();

View File

@ -14,10 +14,9 @@ export class SmartPdf {
constructor() { constructor() {
this._readyDeferred = new plugins.smartpromise.Deferred(); this._readyDeferred = new plugins.smartpromise.Deferred();
this.init();
} }
async init() { async start() {
// setup puppeteer // setup puppeteer
this.headlessBrowser = await plugins.puppeteer.launch(); this.headlessBrowser = await plugins.puppeteer.launch();
@ -36,7 +35,7 @@ export class SmartPdf {
}); });
} }
async close() { async stop() {
const done = plugins.smartpromise.defer<void>(); const done = plugins.smartpromise.defer<void>();
this.htmlServerInstance.close(() => { this.htmlServerInstance.close(() => {
done.resolve(); done.resolve();
@ -76,6 +75,7 @@ export class SmartPdf {
async getPdfForWebsite(websiteUrl: string) { async getPdfForWebsite(websiteUrl: string) {
const page = await this.headlessBrowser.newPage(); const page = await this.headlessBrowser.newPage();
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();
await page.pdf({ await page.pdf({
@ -90,6 +90,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');
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(() => {