Skip to content

Commit

Permalink
Adding F flag to make links pdf/a-1a conform
Browse files Browse the repository at this point in the history
  • Loading branch information
haramon authored and asolntsev committed Mar 7, 2024
1 parent 80a757b commit 78ea68b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand All @@ -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);
}
Expand Down

0 comments on commit 78ea68b

Please sign in to comment.