fix(core): update
This commit is contained in:
parent
56fa53b701
commit
8a308fa9e3
20392
package-lock.json
generated
20392
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
17
package.json
17
package.json
@ -12,22 +12,23 @@
|
|||||||
"build": "(tsbuild --web)"
|
"build": "(tsbuild --web)"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@gitzone/tsbuild": "^2.1.25",
|
"@gitzone/tsbuild": "^2.1.28",
|
||||||
"@gitzone/tsrun": "^1.2.12",
|
"@gitzone/tsrun": "^1.2.18",
|
||||||
"@gitzone/tstest": "^1.0.52",
|
"@gitzone/tstest": "^1.0.59",
|
||||||
"@pushrocks/tapbundle": "^3.2.14",
|
"@pushrocks/tapbundle": "^3.2.14",
|
||||||
"@types/node": "^15.0.1",
|
"@types/node": "^16.10.5",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"tslint-config-prettier": "^1.18.0"
|
"tslint-config-prettier": "^1.18.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^8.0.10",
|
"@pushrocks/smartfile": "^8.0.10",
|
||||||
"@pushrocks/smartnetwork": "^2.0.10",
|
"@pushrocks/smartnetwork": "^2.0.10",
|
||||||
"@pushrocks/smartpromise": "^3.1.5",
|
"@pushrocks/smartpromise": "^3.1.6",
|
||||||
"@pushrocks/smartpuppeteer": "^1.0.21",
|
"@pushrocks/smartpuppeteer": "^1.0.27",
|
||||||
"@pushrocks/smartunique": "^3.0.3",
|
"@pushrocks/smartunique": "^3.0.3",
|
||||||
"@types/express": "^4.17.11",
|
"@types/express": "^4.17.13",
|
||||||
"express": "^4.17.1"
|
"express": "^4.17.1",
|
||||||
|
"pdf-merger-js": "^3.2.1"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"ts/**/*",
|
"ts/**/*",
|
||||||
|
18
test/test.ts
18
test/test.ts
@ -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 () => {
|
tap.test('should create a valid PDFResult', async () => {
|
||||||
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(
|
const writePDfToDisk = async (urlArg: string, fileName: string) => {
|
||||||
'https://maintainedby.lossless.com'
|
const pdfResult = await testSmartPdf.getFullWebsiteAsSinglePdf(urlArg);
|
||||||
);
|
|
||||||
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
|
expect(pdfResult.buffer).to.be.instanceOf(Buffer);
|
||||||
const fs = await import('fs');
|
const fs = await import('fs');
|
||||||
|
|
||||||
if (!fs.existsSync('.nogit/')) {
|
if (!fs.existsSync('.nogit/')) {
|
||||||
fs.mkdirSync('.nogit/');
|
fs.mkdirSync('.nogit/');
|
||||||
}
|
}
|
||||||
fs.writeFileSync('.nogit/sample.pdf', pdfResult.buffer);
|
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 () => {
|
tap.test('should be able to close properly', async () => {
|
||||||
await testSmartPdf.stop();
|
await testSmartPdf.stop();
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
import * as plugins from './smartpdf.plugins';
|
import * as plugins from './smartpdf.plugins';
|
||||||
|
|
||||||
export class PdfCandidate {
|
export class PdfCandidate {
|
||||||
pdfId = plugins.smartunique.shortId();
|
public htmlString: string;
|
||||||
doneDeferred = plugins.smartpromise.defer();
|
public pdfId = plugins.smartunique.shortId();
|
||||||
|
public doneDeferred = plugins.smartpromise.defer();
|
||||||
|
|
||||||
constructor(public htmlString) {}
|
constructor(htmlStringArg: string) {
|
||||||
|
this.htmlString = htmlStringArg;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,7 @@ import * as paths from './smartpdf.paths';
|
|||||||
import { Server } from 'http';
|
import { Server } from 'http';
|
||||||
import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
|
import { PdfCandidate } from './smartpdf.classes.pdfcandidate';
|
||||||
|
|
||||||
declare const document;
|
declare const document: any;
|
||||||
|
|
||||||
import * as interfaces from './interfaces';
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
@ -19,7 +19,7 @@ export class SmartPdf {
|
|||||||
this._readyDeferred = new plugins.smartpromise.Deferred();
|
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
|
// lets set the external browser in case one is provided
|
||||||
this.headlessBrowser = headlessBrowserArg;
|
this.headlessBrowser = headlessBrowserArg;
|
||||||
// setup puppeteer
|
// setup puppeteer
|
||||||
@ -80,7 +80,7 @@ export class SmartPdf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'A4',
|
format: 'a4',
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
preferCSSPageSize: true,
|
preferCSSPageSize: true,
|
||||||
@ -108,7 +108,7 @@ export class SmartPdf {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'A4',
|
format: 'a4',
|
||||||
height: documentWidth,
|
height: documentWidth,
|
||||||
width: documentWidth,
|
width: documentWidth,
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
@ -135,7 +135,7 @@ export class SmartPdf {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'A4',
|
format: 'a4',
|
||||||
height: documentWidth,
|
height: documentWidth,
|
||||||
width: documentWidth,
|
width: documentWidth,
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
@ -149,4 +149,12 @@ export class SmartPdf {
|
|||||||
buffer: pdfBuffer,
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ import * as smartunique from '@pushrocks/smartunique';
|
|||||||
export { smartfile, smartpromise, smartpuppeteer, smartunique, smartnetwork };
|
export { smartfile, smartpromise, smartpuppeteer, smartunique, smartnetwork };
|
||||||
|
|
||||||
// thirdparty
|
// thirdparty
|
||||||
|
import pdfMerger from 'pdf-merger-js';
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
|
|
||||||
export { express };
|
export { pdfMerger, express };
|
||||||
|
Loading…
Reference in New Issue
Block a user