Compare commits

...

4 Commits

Author SHA1 Message Date
46fbb615a0 3.1.5 2024-04-27 12:07:16 +02:00
3df4e103f9 fix(core): update 2024-04-27 12:07:16 +02:00
addff418c6 3.1.4 2024-04-26 13:39:58 +02:00
14d653e701 fix(core): update 2024-04-26 13:39:57 +02:00
4 changed files with 10 additions and 8 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@push.rocks/smartpdf",
"version": "3.1.3",
"version": "3.1.5",
"private": false,
"description": "A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.",
"main": "dist_ts/index.js",

View File

@ -55,8 +55,8 @@ tap.test('should merge pdfs', async () => {
tap.test('should create images from an pdf', async () => {
const pdfObject = await testSmartPdf.readFileToPdfObject('.nogit/combined.pdf');
const images = await testSmartPdf.convertPDFToJPGBytes(pdfObject.buffer);
console.log(images);
const images = await testSmartPdf.convertPDFToPngBytes(pdfObject.buffer);
console.log(images.map((val) => val.length));
});
tap.test('should be able to close properly', async () => {

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@push.rocks/smartpdf',
version: '3.1.3',
version: '3.1.5',
description: 'A library for creating PDFs dynamically from HTML or websites with additional features like merging PDFs.'
}

View File

@ -225,14 +225,14 @@ export class SmartPdf {
return deferred.promise;
}
public async convertPDFToJPGBytes(
public async convertPDFToPngBytes(
pdfBytes: Uint8Array,
options: {
width?: number;
height?: number;
quality?: number;
} = {}
): Promise<Uint8Array[]> {
) {
const { width = 1024, height = 768, quality = 100 } = options;
// Load the PDF document
@ -240,7 +240,7 @@ export class SmartPdf {
const converter = plugins.pdf2pic.fromBuffer(Buffer.from(pdfBytes), {
density: 100, // Image density (DPI)
format: 'jpg', // Image format
format: 'png', // Image format
width, // Output image width
height, // Output image height
quality, // Output image quality
@ -257,6 +257,8 @@ export class SmartPdf {
}
// Resolve all promises and return the array of buffers
return Promise.all(imagePromises);
const imageBuffers = await Promise.all(imagePromises);
const imageUint8Arrays = imageBuffers.map((buffer) => buffer);
return imageUint8Arrays;
}
}