Compare commits
No commits in common. "master" and "v3.2.1" have entirely different histories.
@ -1,12 +1,5 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
## 2025-02-25 - 3.2.2 - fix(SmartPdf)
|
|
||||||
Fix buffer handling for PDF conversion and text extraction
|
|
||||||
|
|
||||||
- Ensure Uint8Array is converted to Node Buffer for PDF conversion.
|
|
||||||
- Correct the PDF page viewport handling by using document dimensions.
|
|
||||||
- Fix extractTextFromPdfBuffer argument type from Uint8Array to Buffer.
|
|
||||||
|
|
||||||
## 2025-02-25 - 3.2.1 - fix(SmartPdf)
|
## 2025-02-25 - 3.2.1 - fix(SmartPdf)
|
||||||
Fix type for extractTextFromPdfBuffer function
|
Fix type for extractTextFromPdfBuffer function
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@push.rocks/smartpdf",
|
"name": "@push.rocks/smartpdf",
|
||||||
"version": "3.2.2",
|
"version": "3.2.1",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.",
|
"description": "A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.",
|
||||||
"main": "dist_ts/index.js",
|
"main": "dist_ts/index.js",
|
||||||
|
@ -3,6 +3,6 @@
|
|||||||
*/
|
*/
|
||||||
export const commitinfo = {
|
export const commitinfo = {
|
||||||
name: '@push.rocks/smartpdf',
|
name: '@push.rocks/smartpdf',
|
||||||
version: '3.2.2',
|
version: '3.2.1',
|
||||||
description: 'A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.'
|
description: 'A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.'
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ export class SmartPdf {
|
|||||||
this.externalBrowserBool = true;
|
this.externalBrowserBool = true;
|
||||||
} else {
|
} else {
|
||||||
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance({
|
this.headlessBrowser = await plugins.smartpuppeteer.getEnvAwareBrowserInstance({
|
||||||
forceNoSandbox: false,
|
forceNoSandbox: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,8 +104,6 @@ export class SmartPdf {
|
|||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
});
|
});
|
||||||
// Convert Uint8Array to Node Buffer
|
|
||||||
const nodePdfBuffer = Buffer.from(pdfBuffer);
|
|
||||||
await page.close();
|
await page.close();
|
||||||
delete this._candidates[pdfCandidate.pdfId];
|
delete this._candidates[pdfCandidate.pdfId];
|
||||||
pdfCandidate.doneDeferred.resolve();
|
pdfCandidate.doneDeferred.resolve();
|
||||||
@ -114,9 +112,9 @@ export class SmartPdf {
|
|||||||
id: pdfCandidate.pdfId,
|
id: pdfCandidate.pdfId,
|
||||||
name: `${pdfCandidate.pdfId}.js`,
|
name: `${pdfCandidate.pdfId}.js`,
|
||||||
metadata: {
|
metadata: {
|
||||||
textExtraction: await this.extractTextFromPdfBuffer(nodePdfBuffer),
|
textExtraction: await this.extractTextFromPdfBuffer(pdfBuffer),
|
||||||
},
|
},
|
||||||
buffer: nodePdfBuffer,
|
buffer: pdfBuffer,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,16 +139,14 @@ export class SmartPdf {
|
|||||||
printBackground: true,
|
printBackground: true,
|
||||||
displayHeaderFooter: false,
|
displayHeaderFooter: false,
|
||||||
});
|
});
|
||||||
// Convert Uint8Array to Node Buffer
|
|
||||||
const nodePdfBuffer = Buffer.from(pdfBuffer);
|
|
||||||
await page.close();
|
await page.close();
|
||||||
return {
|
return {
|
||||||
id: pdfId,
|
id: pdfId,
|
||||||
name: `${pdfId}.js`,
|
name: `${pdfId}.js`,
|
||||||
metadata: {
|
metadata: {
|
||||||
textExtraction: await this.extractTextFromPdfBuffer(nodePdfBuffer),
|
textExtraction: await this.extractTextFromPdfBuffer(pdfBuffer),
|
||||||
},
|
},
|
||||||
buffer: nodePdfBuffer,
|
buffer: pdfBuffer,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,20 +159,12 @@ export class SmartPdf {
|
|||||||
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();
|
||||||
// Use both document.body and document.documentElement to ensure we have a valid height and width.
|
|
||||||
const { documentHeight, documentWidth } = await page.evaluate(() => {
|
const { documentHeight, documentWidth } = await page.evaluate(() => {
|
||||||
return {
|
return {
|
||||||
documentHeight: Math.max(
|
documentHeight: document.body.scrollHeight,
|
||||||
document.body.scrollHeight,
|
documentWidth: document.body.clientWidth,
|
||||||
document.documentElement.scrollHeight
|
|
||||||
) || 1200,
|
|
||||||
documentWidth: Math.max(
|
|
||||||
document.body.clientWidth,
|
|
||||||
document.documentElement.clientWidth
|
|
||||||
) || 1920,
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
// Update viewport height to the full document height.
|
|
||||||
await page.setViewport({
|
await page.setViewport({
|
||||||
width: 1920,
|
width: 1920,
|
||||||
height: documentHeight,
|
height: documentHeight,
|
||||||
@ -189,16 +177,14 @@ export class SmartPdf {
|
|||||||
scale: 1,
|
scale: 1,
|
||||||
pageRanges: '1',
|
pageRanges: '1',
|
||||||
});
|
});
|
||||||
// Convert Uint8Array to Node Buffer
|
|
||||||
const nodePdfBuffer = Buffer.from(pdfBuffer);
|
|
||||||
await page.close();
|
await page.close();
|
||||||
return {
|
return {
|
||||||
id: pdfId,
|
id: pdfId,
|
||||||
name: `${pdfId}.js`,
|
name: `${pdfId}.js`,
|
||||||
metadata: {
|
metadata: {
|
||||||
textExtraction: await this.extractTextFromPdfBuffer(nodePdfBuffer),
|
textExtraction: await this.extractTextFromPdfBuffer(pdfBuffer),
|
||||||
},
|
},
|
||||||
buffer: nodePdfBuffer,
|
buffer: pdfBuffer,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +212,7 @@ export class SmartPdf {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async extractTextFromPdfBuffer(pdfBufferArg: Buffer): Promise<string> {
|
public async extractTextFromPdfBuffer(pdfBufferArg: Uint8Array): Promise<string> {
|
||||||
const deferred = plugins.smartpromise.defer<string>();
|
const deferred = plugins.smartpromise.defer<string>();
|
||||||
const pdfParser: any = new plugins.pdf2json();
|
const pdfParser: any = new plugins.pdf2json();
|
||||||
pdfParser.on('pdfParser_dataReady', (pdfData: any) => {
|
pdfParser.on('pdfParser_dataReady', (pdfData: any) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user