Compare commits

...

18 Commits

Author SHA1 Message Date
377318a62a 2.0.13 2022-01-05 14:19:40 +01:00
671c871304 fix(core): update 2022-01-05 14:19:39 +01:00
e0cc6b5655 2.0.12 2022-01-05 14:17:43 +01:00
e74b44b49c fix(core): update 2022-01-05 14:17:43 +01:00
d6f0d88d4a 2.0.11 2021-10-14 16:04:58 +02:00
9674e5b8dc fix(core): update 2021-10-14 16:04:58 +02:00
ea4cf777a9 2.0.10 2021-10-14 10:59:45 +02:00
8a308fa9e3 fix(core): update 2021-10-14 10:59:45 +02:00
56fa53b701 2.0.9 2021-04-29 15:19:15 +00:00
2a4ddd4e41 fix(core): update 2021-04-29 15:19:14 +00:00
3d8a63fddd 2.0.8 2021-04-29 09:32:13 +00:00
9d9b1d0399 fix(core): update 2021-04-29 09:32:12 +00:00
739d60d410 2.0.7 2021-04-14 11:35:06 +00:00
9003034d0d fix(core): update 2021-04-14 11:35:05 +00:00
5002513d21 2.0.6 2021-04-14 11:34:34 +00:00
12ede2be02 fix(core): update 2021-04-14 11:34:33 +00:00
163ec2bd50 2.0.5 2021-03-06 15:33:08 +00:00
7744839613 fix(core): update 2021-03-06 15:33:07 +00:00
7 changed files with 19396 additions and 3485 deletions

22786
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{
"name": "@pushrocks/smartpdf",
"version": "2.0.4",
"version": "2.0.13",
"private": false,
"description": "create pdfs on the fly",
"main": "dist_ts/index.js",
@ -8,27 +8,27 @@
"author": "Lossless GmbH",
"license": "MIT",
"scripts": {
"test": "(tstest test/)",
"format": "(gitzone format)",
"build": "(tsbuild)"
"test": "(tstest test/ --web)",
"build": "(tsbuild --web)"
},
"devDependencies": {
"@gitzone/tsbuild": "^2.1.25",
"@gitzone/tsrun": "^1.2.12",
"@gitzone/tstest": "^1.0.52",
"@pushrocks/tapbundle": "^3.2.14",
"@types/node": "^14.14.31",
"@gitzone/tsbuild": "^2.1.28",
"@gitzone/tsrun": "^1.2.18",
"@gitzone/tstest": "^1.0.60",
"@pushrocks/tapbundle": "^3.2.15",
"@types/node": "^17.0.8",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0"
},
"dependencies": {
"@pushrocks/smartfile": "^8.0.8",
"@pushrocks/smartnetwork": "^1.1.22",
"@pushrocks/smartpromise": "^3.1.3",
"@pushrocks/smartpuppeteer": "^1.0.21",
"@pushrocks/smartfile": "^9.0.5",
"@pushrocks/smartnetwork": "^2.0.10",
"@pushrocks/smartpromise": "^3.1.6",
"@pushrocks/smartpuppeteer": "^1.0.36",
"@pushrocks/smartunique": "^3.0.3",
"@types/express": "^4.17.11",
"express": "^4.17.1"
"@types/express": "^4.17.13",
"express": "^4.17.2",
"pdf-merger-js": "^3.2.1"
},
"files": [
"ts/**/*",

View File

@ -29,7 +29,6 @@ Platform support | [![Supports Windows 10](https://badgen.net/badge/supports%20W
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
## Contribution
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)

View File

@ -25,18 +25,28 @@ tap.test('should create a pdf from website as single page PDF', async () => {
});
tap.test('should create a valid PDFResult', async () => {
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(
'https://maintainedby.lossless.com'
);
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
const fs = await import('fs');
const writePDfToDisk = async (urlArg: string, fileName: string) => {
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(urlArg);
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
const fs = await import('fs');
if (!fs.existsSync('.nogit/')) {
fs.mkdirSync('.nogit/');
}
fs.writeFileSync('.nogit/sample.pdf', pdfResult.buffer);
if (!fs.existsSync('.nogit/')) {
fs.mkdirSync('.nogit/');
}
fs.writeFileSync(`.nogit/${fileName}`, pdfResult.buffer);
};
await writePDfToDisk('https://maintainedby.lossless.com/', '1.pdf')
await writePDfToDisk('https://lossless.com/', '2.pdf')
});
tap.test('should combine pdfs', async () => {
const fs = await import('fs');
const buffer1 = fs.readFileSync('.nogit/1.pdf');
const buffer2 = fs.readFileSync('.nogit/2.pdf');
fs.writeFileSync(`.nogit/combined.pdf`, await testSmartPdf.mergePdfBuffers([buffer1, buffer2]));
})
tap.test('should be able to close properly', async () => {
await testSmartPdf.stop();
});

View File

@ -1,8 +1,11 @@
import * as plugins from './smartpdf.plugins';
export class PdfCandidate {
pdfId = plugins.smartunique.shortId();
doneDeferred = plugins.smartpromise.defer();
public htmlString: string;
public pdfId = plugins.smartunique.shortId();
public doneDeferred = plugins.smartpromise.defer();
constructor(public htmlString) {}
constructor(htmlStringArg: string) {
this.htmlString = htmlStringArg;
}
}

View File

@ -3,7 +3,7 @@ import * as paths from './smartpdf.paths';
import { Server } from 'http';
import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
declare const document;
declare const document: any;
import * as interfaces from './interfaces';
@ -19,7 +19,7 @@ export class SmartPdf {
this._readyDeferred = new plugins.smartpromise.Deferred();
}
async start(headlessBrowserArg?) {
async start(headlessBrowserArg?: plugins.smartpuppeteer.puppeteer.Browser) {
// lets set the external browser in case one is provided
this.headlessBrowser = headlessBrowserArg;
// setup puppeteer
@ -39,7 +39,7 @@ export class SmartPdf {
});
this.htmlServerInstance = plugins.http.createServer(app);
const smartnetworkInstance = new plugins.smartnetwork.SmartNetwork();
const portAvailable = smartnetworkInstance.isLocalPortAvailable(3210);
const portAvailable = smartnetworkInstance.isLocalPortUnused(3210);
this.htmlServerInstance.listen(3210, 'localhost');
this.htmlServerInstance.on('listening', () => {
this._readyDeferred.resolve();
@ -68,6 +68,10 @@ export class SmartPdf {
const pdfCandidate = new PdfCandidate(htmlStringArg);
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
const page = await this.headlessBrowser.newPage();
await page.setViewport({
height: 842,
width: 595,
})
const response = await page.goto(`http://localhost:3210/${pdfCandidate.pdfId}`, {
waitUntil: 'networkidle2',
});
@ -80,7 +84,7 @@ export class SmartPdf {
}
const pdfBuffer = await page.pdf({
format: 'A4',
format: 'a4',
printBackground: true,
displayHeaderFooter: false,
preferCSSPageSize: true,
@ -108,7 +112,7 @@ export class SmartPdf {
};
});
const pdfBuffer = await page.pdf({
format: 'A4',
format: 'a4',
height: documentWidth,
width: documentWidth,
printBackground: true,
@ -135,7 +139,7 @@ export class SmartPdf {
};
});
const pdfBuffer = await page.pdf({
format: 'A4',
format: 'a4',
height: documentWidth,
width: documentWidth,
printBackground: true,
@ -149,4 +153,12 @@ export class SmartPdf {
buffer: pdfBuffer,
};
}
public async mergePdfBuffers(pdfBuffers: Buffer[]): Promise<Buffer> {
const merger = new plugins.pdfMerger();
for (const buffer of pdfBuffers) {
merger.add(buffer);
}
return merger.saveAsBuffer();
}
}

View File

@ -14,6 +14,7 @@ import * as smartunique from '@pushrocks/smartunique';
export { smartfile, smartpromise, smartpuppeteer, smartunique, smartnetwork };
// thirdparty
import pdfMerger from 'pdf-merger-js';
import express from 'express';
export { express };
export { pdfMerger, express };