From aac8dd643901b1f5df9ab3598589d1e3428921cd Mon Sep 17 00:00:00 2001 From: Orban Gergo Date: Tue, 22 Sep 2026 23:44:28 +0300 Subject: [PATCH] fix(imagemagick): handle multi-page PDF outputs and improve rasterization quality (#593) --- src/converters/imagemagick.ts | 5 +++++ src/converters/main.ts | 28 +++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/converters/imagemagick.ts b/src/converters/imagemagick.ts index e3fc53c2..767dd081 100644 --- a/src/converters/imagemagick.ts +++ b/src/converters/imagemagick.ts @@ -461,6 +461,11 @@ export function convert( } } + // Increase rasterization quality for PDF input + if (fileType === "pdf") { + inputArgs.push("-density", "300"); + } + // Handle EMF files specifically to avoid LibreOffice delegate issues if (fileType === "emf") { // Use direct conversion without delegates for EMF files diff --git a/src/converters/main.ts b/src/converters/main.ts index 6980cc69..372ac07a 100644 --- a/src/converters/main.ts +++ b/src/converters/main.ts @@ -1,5 +1,7 @@ import { Cookie } from "elysia"; import db from "../db/db"; +import fs from "node:fs"; +import path from "node:path"; import { MAX_CONVERT_PROCESS } from "../helpers/env"; import { normalizeFiletype, normalizeOutputFiletype } from "../helpers/normalizeFiletype"; import { convert as convertassimp, properties as propertiesassimp } from "./assimp"; @@ -187,7 +189,31 @@ export async function handleConvert( mainConverter(filePath, fileType, convertTo, targetPath, {}, converterName) .then((r) => { if (jobId.value) { - query.run(jobId.value, fileName, newFileName, r); + const dir = path.dirname(targetPath); + const parsed = path.parse(targetPath); + + const outputFiles = fs + .readdirSync(dir) + .filter((f) => { + if (f === parsed.base) { + return true; + } + + return ( + f.startsWith(`${parsed.name}-`) && + f.endsWith(parsed.ext) && + /^\d+$/.test(f.slice(parsed.name.length + 1, -parsed.ext.length)) + ); + }) + .sort((a, b) => a.localeCompare(b, undefined, { numeric: true })); + + if (outputFiles.length > 0) { + for (const outputFile of outputFiles) { + query.run(jobId.value, fileName, outputFile, r); + } + } else { + query.run(jobId.value, fileName, newFileName, r); + } } resolve(r); })