From b8df298953908da85c2d812313ddf2ba43d48c44 Mon Sep 17 00:00:00 2001 From: Kellermorph Date: Thu, 20 Aug 2026 11:21:22 +0200 Subject: [PATCH] fix --- sources/pdf_links.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/sources/pdf_links.cpp b/sources/pdf_links.cpp index 5cf176f76..810aa7284 100644 --- a/sources/pdf_links.cpp +++ b/sources/pdf_links.cpp @@ -492,13 +492,17 @@ void convertComponentInfoAnnotations(const QString &pdfPath, QByteArray contents = annotations[annotIndex].contents.toUtf8(); - // Replace /Subtype /Link with /Subtype /Text, bounded to current object. - // Search only the bytes we just appended (the current annotation header). - int searchStart = out.size() - (aDictOpen - pos); - int subTypePos = out.indexOf("/Subtype /Link", searchStart); - if (subTypePos != -1) { + // Replace /Subtype /Link with /Subtype /Text, bounded to the enclosing + // PDF object. Anchoring to " 0 obj" prevents hitting /Subtype /Link + // from a cross-ref annotation that sits between the previous marker + // and the current annotation on the same page. + int objStart = body.lastIndexOf(" 0 obj", aDictOpen); + int subTypeInBody = (objStart != -1) + ? body.indexOf("/Subtype /Link", objStart) : -1; + int subTypePos = (subTypeInBody != -1 && subTypeInBody < aDictOpen) + ? out.size() - (aDictOpen - subTypeInBody) : -1; + if (subTypePos != -1) out.replace(subTypePos, 14, "/Subtype /Text"); - } // Encode as UTF-16BE hex with BOM for proper Unicode support (Umlauten etc.). // PDF spec: hex strings starting with FE FF are interpreted as UTF-16BE.