fix(imagemagick): handle multi-page PDF outputs and improve rasterization quality (#593)

This commit is contained in:
Orban Gergo
2026-09-22 23:44:28 +03:00
committed by GitHub
parent 6fdd24ccb1
commit aac8dd6439
2 changed files with 32 additions and 1 deletions
+5
View File
@@ -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
+27 -1
View File
@@ -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);
})