From 78ea68b117682751546726ecfc29857417637d55 Mon Sep 17 00:00:00 2001 From: Harald Amon Date: Wed, 6 Mar 2024 10:11:43 +0100 Subject: [PATCH] Adding F flag to make links pdf/a-1a conform --- .../xhtmlrenderer/pdf/ITextOutputDevice.java | 27 ++++++++++--------- .../xhtmlrenderer/pdf/ITextOutputDevice.java | 27 ++++++++++--------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/flying-saucer-pdf-itext5/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java b/flying-saucer-pdf-itext5/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java index d8399e8e2..066c403fb 100644 --- a/flying-saucer-pdf-itext5/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java +++ b/flying-saucer-pdf-itext5/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java @@ -31,6 +31,7 @@ import com.itextpdf.text.pdf.PdfDestination; import com.itextpdf.text.pdf.PdfImportedPage; import com.itextpdf.text.pdf.PdfName; +import com.itextpdf.text.pdf.PdfNumber; import com.itextpdf.text.pdf.PdfOutline; import com.itextpdf.text.pdf.PdfReader; import com.itextpdf.text.pdf.PdfTextArray; @@ -272,12 +273,7 @@ private void processLink(RenderingContext c, Box box) { targetArea.setBorder(0); targetArea.setBorderWidth(0); - PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), - targetArea.getRight(), targetArea.getTop(), action); - annot.put(PdfName.SUBTYPE, PdfName.LINK); - annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); - annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); - _writer.addAnnotation(annot); + addLinkAnnotation(action, targetArea); } } else { int boxTop = box.getAbsY(); @@ -292,19 +288,24 @@ private void processLink(RenderingContext c, Box box) { if (targetArea == null) { return; } - PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), targetArea.getRight(), - targetArea.getTop(), action); - annot.put(PdfName.SUBTYPE, PdfName.LINK); - - annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); - annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); - _writer.addAnnotation(annot); + addLinkAnnotation(action, targetArea); } } } } } + private void addLinkAnnotation(final PdfAction action, final com.itextpdf.text.Rectangle targetArea) { + PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), + targetArea.getRight(), targetArea.getTop(), action); + annot.put(PdfName.SUBTYPE, PdfName.LINK); + annot.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT)); + + annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); + annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); + _writer.addAnnotation(annot); + } + public com.itextpdf.text.Rectangle createLocalTargetArea(RenderingContext c, Box box) { return createLocalTargetArea(c, box, false); } diff --git a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java index ad06eff1d..1b66be7e7 100644 --- a/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java +++ b/flying-saucer-pdf/src/main/java/org/xhtmlrenderer/pdf/ITextOutputDevice.java @@ -33,6 +33,7 @@ import com.lowagie.text.pdf.PdfImportedPage; import com.lowagie.text.pdf.PdfIndirectReference; import com.lowagie.text.pdf.PdfName; +import com.lowagie.text.pdf.PdfNumber; import com.lowagie.text.pdf.PdfOutline; import com.lowagie.text.pdf.PdfReader; import com.lowagie.text.pdf.PdfString; @@ -277,12 +278,7 @@ private void processLink(RenderingContext c, Box box) { targetArea.setBorder(0); targetArea.setBorderWidth(0); - PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), - targetArea.getRight(), targetArea.getTop(), action); - annot.put(PdfName.SUBTYPE, PdfName.LINK); - annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); - annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); - _writer.addAnnotation(annot); + addLinkAnnotation(action, targetArea); } } } else { @@ -292,18 +288,23 @@ private void processLink(RenderingContext c, Box box) { if (targetArea == null) { return; } - PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), targetArea.getRight(), - targetArea.getTop(), action); - annot.put(PdfName.SUBTYPE, PdfName.LINK); - - annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); - annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); - _writer.addAnnotation(annot); + addLinkAnnotation(action, targetArea); } } } } + private void addLinkAnnotation(final PdfAction action, final com.lowagie.text.Rectangle targetArea) { + PdfAnnotation annot = new PdfAnnotation(_writer, targetArea.getLeft(), targetArea.getBottom(), + targetArea.getRight(), targetArea.getTop(), action); + annot.put(PdfName.SUBTYPE, PdfName.LINK); + annot.put(PdfName.F, new PdfNumber(PdfAnnotation.FLAGS_PRINT)); + + annot.setBorderStyle(new PdfBorderDictionary(0.0f, 0)); + annot.setBorder(new PdfBorderArray(0.0f, 0.0f, 0)); + _writer.addAnnotation(annot); + } + public com.lowagie.text.Rectangle createLocalTargetArea(RenderingContext c, Box box) { return createLocalTargetArea(c, box, false); }