fix(pdf-compress): remove /screen preset that destroys font encoding

The -dPDFSETTINGS=/screen GS preset overwrites font encoding tables,
producing garbled text in output PDFs. Replace with individual params
that ONLY compress images while preserving fonts intact.

Three quality levels via GS (no Stirling dependency):
- extreme: 100 DPI, QFactor 1.2 (~quality 35)
- high: 150 DPI, QFactor 0.76 (~quality 50)
- balanced: 200 DPI, QFactor 0.4 (~quality 70)

Route all UI modes through the GS endpoint with level parameter.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
AI Assistant
2026-03-13 17:19:42 +02:00
parent 9e73dc3cb9
commit d75fcb1d1c
2 changed files with 102 additions and 47 deletions
@@ -1662,15 +1662,10 @@ function PdfReducer() {
try {
const formData = new FormData();
formData.append("fileInput", file);
// All modes use the GS endpoint with a level parameter
formData.append("level", mode === "extreme" ? "extreme" : mode === "max" ? "high" : "balanced");
let endpoint = "/api/compress-pdf";
if (mode === "extreme") {
endpoint = "/api/compress-pdf/extreme";
} else {
formData.append("optimizeLevel", mode === "max" ? "4" : "2");
}
const res = await fetch(endpoint, {
const res = await fetch("/api/compress-pdf/extreme", {
method: "POST",
body: formData,
});
@@ -1765,17 +1760,18 @@ function PdfReducer() {
className="mt-1 w-full rounded-md border bg-background px-3 py-2 text-sm"
>
<option value="extreme">
Compresie extremă multi-pass (recomandat)
Extremă imagini 100 DPI, calitate scăzută
</option>
<option value="max">Compresie maximă single-pass</option>
<option value="balanced">Echilibrat</option>
<option value="max">Puternică imagini 150 DPI, calitate medie (recomandat)</option>
<option value="balanced">Echilibrată imagini 200 DPI, calitate bună</option>
</select>
{mode === "extreme" && (
<p className="text-xs text-muted-foreground">
Aplică compresie maximă în mai multe treceri succesive. Durează mai
mult dar reduce semnificativ dimensiunea.
</p>
)}
<p className="text-xs text-muted-foreground">
{mode === "extreme"
? "Reduce maxim dimensiunea. Imaginile pot pierde detalii fine."
: mode === "max"
? "Balanță bună între dimensiune și calitate. Recomandat pentru majoritatea fișierelor."
: "Pierdere minimă de calitate. Ideal pentru documente cu grafice detaliate."}
</p>
</div>
<Button onClick={handleCompress} disabled={!file || loading}>