Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
796aa905d2 | |||
253fb95143 | |||
f3ea075b72 | |||
af725a7f78 |
4
package-lock.json
generated
4
package-lock.json
generated
@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "2.0.16",
|
"version": "2.0.18",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "2.0.16",
|
"version": "2.0.18",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@pushrocks/smartfile": "^9.0.5",
|
"@pushrocks/smartfile": "^9.0.5",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartpdf",
|
"name": "@pushrocks/smartpdf",
|
||||||
"version": "2.0.16",
|
"version": "2.0.18",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "create pdfs on the fly",
|
"description": "create pdfs on the fly",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -13,11 +13,11 @@ tap.test('should start the instance', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a pdf from html string', async () => {
|
tap.test('should create a pdf from html string', async () => {
|
||||||
await testSmartPdf.getPdfResultForHtmlString('hi');
|
await testSmartPdf.getA4PdfResultForHtmlString('hi');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a pdf from html string', async () => {
|
tap.test('should create a pdf from html string', async () => {
|
||||||
await testSmartPdf.getPdfResultForHtmlString('hi');
|
await testSmartPdf.getA4PdfResultForHtmlString('hi');
|
||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should create a pdf from website as A4', async () => {
|
tap.test('should create a pdf from website as A4', async () => {
|
||||||
|
@ -63,7 +63,7 @@ export class SmartPdf {
|
|||||||
/**
|
/**
|
||||||
* returns a pdf for a given html string;
|
* returns a pdf for a given html string;
|
||||||
*/
|
*/
|
||||||
async getPdfResultForHtmlString(htmlStringArg: string): Promise<interfaces.IPdfResult> {
|
async getA4PdfResultForHtmlString(htmlStringArg: string): Promise<interfaces.IPdfResult> {
|
||||||
await this._readyDeferred.promise;
|
await this._readyDeferred.promise;
|
||||||
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
const pdfCandidate = new PdfCandidate(htmlStringArg);
|
||||||
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
this._candidates[pdfCandidate.pdfId] = pdfCandidate;
|
||||||
@ -84,10 +84,10 @@ export class SmartPdf {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'a4',
|
width: 794,
|
||||||
|
height: 1122,
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
preferCSSPageSize: true,
|
|
||||||
});
|
});
|
||||||
await page.close();
|
await page.close();
|
||||||
delete this._candidates[pdfCandidate.pdfId];
|
delete this._candidates[pdfCandidate.pdfId];
|
||||||
@ -105,6 +105,10 @@ export class SmartPdf {
|
|||||||
|
|
||||||
async getPdfResultForWebsite(websiteUrl: string): Promise<interfaces.IPdfResult> {
|
async getPdfResultForWebsite(websiteUrl: string): Promise<interfaces.IPdfResult> {
|
||||||
const page = await this.headlessBrowser.newPage();
|
const page = await this.headlessBrowser.newPage();
|
||||||
|
await page.setViewport({
|
||||||
|
width: 1980,
|
||||||
|
height: 1200,
|
||||||
|
});
|
||||||
await page.emulateMediaType('screen');
|
await page.emulateMediaType('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();
|
||||||
@ -115,12 +119,10 @@ export class SmartPdf {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'a4',
|
height: documentHeight,
|
||||||
height: documentWidth,
|
|
||||||
width: documentWidth,
|
width: documentWidth,
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
preferCSSPageSize: true,
|
|
||||||
});
|
});
|
||||||
await page.close();
|
await page.close();
|
||||||
return {
|
return {
|
||||||
@ -135,22 +137,30 @@ export class SmartPdf {
|
|||||||
|
|
||||||
async getFullWebsiteAsSinglePdf(websiteUrl: string): Promise<interfaces.IPdfResult> {
|
async getFullWebsiteAsSinglePdf(websiteUrl: string): Promise<interfaces.IPdfResult> {
|
||||||
const page = await this.headlessBrowser.newPage();
|
const page = await this.headlessBrowser.newPage();
|
||||||
|
await page.setViewport({
|
||||||
|
width: 1920,
|
||||||
|
height: 1200,
|
||||||
|
});
|
||||||
page.emulateMediaType('screen');
|
page.emulateMediaType('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(() => {
|
||||||
return {
|
return {
|
||||||
documentHeight: document.height,
|
documentHeight: document.body.scrollHeight,
|
||||||
documentWidth: document.width,
|
documentWidth: document.body.clientWidth,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
await page.setViewport({
|
||||||
|
width: 1920,
|
||||||
|
height: documentHeight,
|
||||||
|
});
|
||||||
const pdfBuffer = await page.pdf({
|
const pdfBuffer = await page.pdf({
|
||||||
format: 'a4',
|
height: documentHeight,
|
||||||
height: documentWidth,
|
width: 1920,
|
||||||
width: documentWidth,
|
|
||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
preferCSSPageSize: true,
|
scale: 1,
|
||||||
|
pageRanges: '1'
|
||||||
});
|
});
|
||||||
await page.close();
|
await page.close();
|
||||||
return {
|
return {
|
||||||
|
Reference in New Issue
Block a user