diff --git a/package-lock.json b/package-lock.json index 3972c17..8340460 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,6 @@ "dependencies": { "gm": "^1.25.0", "neat-csv": "^7.0.0", - "pdf-lib": "^1.17.1", "serialport": "^11.0.1", "svelte-local-storage-store": "^0.5.0", "throttle-debounce": "^5.0.0" @@ -619,22 +618,6 @@ "node": ">= 8" } }, - "node_modules/@pdf-lib/standard-fonts": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/@pdf-lib/standard-fonts/-/standard-fonts-1.0.0.tgz", - "integrity": "sha512-hU30BK9IUN/su0Mn9VdlVKsWBS6GyhVfqjwl1FjZN4TxP6cCw0jP2w7V3Hf5uX7M0AZJ16vey9yE0ny7Sa59ZA==", - "dependencies": { - "pako": "^1.0.6" - } - }, - "node_modules/@pdf-lib/upng": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@pdf-lib/upng/-/upng-1.0.1.tgz", - "integrity": "sha512-dQK2FUMQtowVP00mtIksrlZhdFXQZPC+taih1q4CvPZ5vqdxR/LKBaFg0oAfzd1GlHZXXSPdQfzQnt+ViGvEIQ==", - "dependencies": { - "pako": "^1.0.10" - } - }, "node_modules/@playwright/test": { "version": "1.36.2", "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.36.2.tgz", @@ -3172,11 +3155,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/pako": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz", - "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw==" - }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", @@ -3240,22 +3218,6 @@ "node": "*" } }, - "node_modules/pdf-lib": { - "version": "1.17.1", - "resolved": "https://registry.npmjs.org/pdf-lib/-/pdf-lib-1.17.1.tgz", - "integrity": "sha512-V/mpyJAoTsN4cnP31vc0wfNA1+p20evqqnap0KLoRUN0Yk/p3wN52DOEsL4oBFcLdb76hlpKPtzJIgo67j/XLw==", - "dependencies": { - "@pdf-lib/standard-fonts": "^1.0.0", - "@pdf-lib/upng": "^1.0.1", - "pako": "^1.0.11", - "tslib": "^1.11.1" - } - }, - "node_modules/pdf-lib/node_modules/tslib": { - "version": "1.14.1", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", - "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==" - }, "node_modules/picocolors": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.0.tgz", diff --git a/package.json b/package.json index f788b81..8b96ca1 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,6 @@ "dependencies": { "gm": "^1.25.0", "neat-csv": "^7.0.0", - "pdf-lib": "^1.17.1", "serialport": "^11.0.1", "svelte-local-storage-store": "^0.5.0", "throttle-debounce": "^5.0.0" diff --git a/src/lib/server/image.ts b/src/lib/server/image.ts index ea880e8..1560e90 100644 --- a/src/lib/server/image.ts +++ b/src/lib/server/image.ts @@ -1,4 +1,3 @@ -import { PDFDocument } from 'pdf-lib'; import { convertPdfToImage } from './pdf'; import { identify, imageMagick } from './imageMagick'; @@ -59,37 +58,9 @@ export async function imageToZpl( export async function pdfToImage(buffer: Buffer | ArrayBuffer, dpi = 300) { const pdfDataBuffer = Buffer.from(buffer); + const image = await convertPdfToImage(pdfDataBuffer, 1, 10); - const pdfDoc = await PDFDocument.load(pdfDataBuffer); - const page = pdfDoc.getPage(0); - const { width: widthInPoints, height: heightInPoints } = page.getSize(); - const rotation = page.getRotation(); - - const { width: widthInPointsRotated, height: heightInPointsRotated } = rotateDimension( - { width: widthInPoints, height: heightInPoints }, - rotation.type === 'degrees' ? rotation.angle : toDegree(rotation.angle) - ); - - const width = Math.round((widthInPointsRotated / 72) * dpi); - const height = Math.round((heightInPointsRotated / 72) * dpi); - - const image = await convertPdfToImage(pdfDataBuffer, 1, 10, width, height); - - return { image, width, height }; -} - -function rotateDimension({ width, height }: Dimensions, rotationDegrees: number) { - if (rotationDegrees % 180 !== 0) { - return { - width: height, - height: width - }; - } - - return { - width, - height - }; + return image; } function bufferToBitBuffer(inputBuffer: Buffer): Buffer { @@ -139,10 +110,6 @@ function calculateRotation(imageSize: Dimensions, pageSize: Dimensions): number return imageIsLandscape !== pageIsLandscape ? 90 : 0; } -function toDegree(radian: number) { - return (radian * 180) / Math.PI; -} - function isDecimal(num: number) { return num % 1 !== 0; } diff --git a/src/lib/server/pdf.ts b/src/lib/server/pdf.ts index 69146cd..a1ddbd9 100644 --- a/src/lib/server/pdf.ts +++ b/src/lib/server/pdf.ts @@ -5,8 +5,6 @@ export async function convertPdfToImage( buffer: Buffer, page: number, dpmm: number, - width: number, - height: number ) { const pageSetup = `pdf[${page - 1}]`; @@ -14,7 +12,6 @@ export async function convertPdfToImage( imageMagick(buffer, pageSetup) .in('-define', 'pdf:use-cropbox=true') .density(dpmmToDpi(dpmm), dpmmToDpi(dpmm)) - .resize(width, height, '!') .quality(0) .compress('jpeg') .stream('png', (error, stdout) => { diff --git a/src/routes/api/[printer]/pdf/+server.ts b/src/routes/api/[printer]/pdf/+server.ts index c4eac58..a4dfd2a 100644 --- a/src/routes/api/[printer]/pdf/+server.ts +++ b/src/routes/api/[printer]/pdf/+server.ts @@ -14,7 +14,7 @@ export const POST: RequestHandler = async ({ params, request }) => { const { width, height } = mmToPixels(printer.dpmm, printer.widthMm, printer.heightMm); - const { image } = await pdfToImage(Buffer.from(await request.arrayBuffer())); + const image = await pdfToImage(Buffer.from(await request.arrayBuffer())); const zpl = await imageToZpl(image, width, height); await print(zpl, printerIdentifier);