Skip to content

Commit c9bfbdc

Browse files
author
Dmitry Radchuk
committed
Add Annot structure for markup annotations
DEVSIX-7966
1 parent ecf88c8 commit c9bfbdc

File tree

11 files changed

+8
-9
lines changed

11 files changed

+8
-9
lines changed

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfPage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ This file is part of the iText (R) project.
3131
import com.itextpdf.kernel.geom.Rectangle;
3232
import com.itextpdf.kernel.pdf.action.PdfAction;
3333
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
34+
import com.itextpdf.kernel.pdf.annot.PdfMarkupAnnotation;
3435
import com.itextpdf.kernel.pdf.filespec.PdfFileSpec;
3536
import com.itextpdf.kernel.pdf.tagging.PdfStructTreeRoot;
3637
import com.itextpdf.kernel.pdf.tagging.StandardRoles;
@@ -857,6 +858,10 @@ public PdfPage addAnnotation(int index, PdfAnnotation annotation, boolean tagAnn
857858
if (getDocument().isTagged()) {
858859
if (tagAnnotation) {
859860
TagTreePointer tagPointer = getDocument().getTagStructureContext().getAutoTaggingPointer();
861+
if (annotation instanceof PdfMarkupAnnotation && StandardRoles.DOCUMENT.equals(tagPointer.getRole())
862+
&& PdfVersion.PDF_1_4.compareTo(getDocument().getPdfVersion()) < 0) {
863+
tagPointer.addTag(StandardRoles.ANNOT);
864+
}
860865
PdfPage prevPage = tagPointer.getCurrentPage();
861866
tagPointer.setPageForTagging(this).addAnnotationTag(annotation);
862867
if (prevPage != null) {

layout/src/test/java/com/itextpdf/layout/PdfUA2AnnotationsTest.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ public void pdfUA2FileAttachmentAnnotTest() throws IOException, XMPException, In
144144
PdfPage pdfPage = pdfDocument.addNewPage();
145145
Rectangle rect = new Rectangle(100, 650, 400, 100);
146146
createSimplePdfUA2Document(pdfDocument);
147-
TagTreePointer tagPointer = pdfDocument.getTagStructureContext().getAutoTaggingPointer();
148-
tagPointer.addTag(StandardRoles.ANNOT);
149147
PdfFileSpec fs = PdfFileSpec.createEmbeddedFileSpec(
150148
pdfDocument, "file".getBytes(StandardCharsets.UTF_8), "description", "file.txt", null, null, null);
151149
PdfFileAttachmentAnnotation annot = new PdfFileAttachmentAnnotation(rect, fs);
@@ -189,8 +187,6 @@ public void pdfUA2RubberStampAnnotationsTest() throws IOException, XMPException,
189187
try (PdfDocument pdfDocument = new PdfDocument(
190188
new PdfWriter(outFile, new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0)))) {
191189
createSimplePdfUA2Document(pdfDocument);
192-
TagTreePointer tagPointer = pdfDocument.getTagStructureContext().getAutoTaggingPointer();
193-
tagPointer.addTag(StandardRoles.ANNOT);
194190
PdfPage pdfPage = pdfDocument.addNewPage();
195191
PdfStampAnnotation stamp = new PdfStampAnnotation(new Rectangle(0, 0, 100, 50));
196192
stamp.setStampName(PdfName.Approved);
@@ -257,8 +253,6 @@ public void pdfUA2InkAnnotationsTest() throws IOException, XMPException, Interru
257253
try (PdfDocument pdfDocument = new PdfDocument(
258254
new PdfWriter(outFile, new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0)))) {
259255
createSimplePdfUA2Document(pdfDocument);
260-
TagTreePointer tagPointer = pdfDocument.getTagStructureContext().getAutoTaggingPointer();
261-
tagPointer.addTag(StandardRoles.ANNOT);
262256
PdfPage pdfPage = pdfDocument.addNewPage();
263257
PdfInkAnnotation ink = createInkAnnotation();
264258
pdfPage.addAnnotation(ink);
@@ -293,8 +287,6 @@ public void pdfUA2RedactionAnnotationsTest() throws IOException, XMPException, I
293287
try (PdfDocument pdfDocument = new PdfDocument(
294288
new PdfWriter(outFile, new WriterProperties().setPdfVersion(PdfVersion.PDF_2_0)))) {
295289
createSimplePdfUA2Document(pdfDocument);
296-
TagTreePointer tagPointer = pdfDocument.getTagStructureContext().getAutoTaggingPointer();
297-
tagPointer.addTag(StandardRoles.ANNOT);
298290
PdfPage pdfPage = pdfDocument.addNewPage();
299291
PdfRedactAnnotation redact = createRedactionAnnotation();
300292
pdfPage.addAnnotation(redact);

pdfa/src/test/java/com/itextpdf/pdfa/PdfA1AnnotationCheckTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ This file is part of the iText (R) project.
3333
import com.itextpdf.kernel.pdf.PdfPage;
3434
import com.itextpdf.kernel.pdf.PdfStream;
3535
import com.itextpdf.kernel.pdf.PdfString;
36+
import com.itextpdf.kernel.pdf.PdfVersion;
3637
import com.itextpdf.kernel.pdf.PdfWriter;
38+
import com.itextpdf.kernel.pdf.WriterProperties;
3739
import com.itextpdf.kernel.pdf.annot.PdfAnnotation;
3840
import com.itextpdf.kernel.pdf.annot.PdfFileAttachmentAnnotation;
3941
import com.itextpdf.kernel.pdf.annot.PdfMarkupAnnotation;
@@ -215,7 +217,7 @@ public void annotationCheckTest08() throws IOException, InterruptedException {
215217
String outPdf = destinationFolder + "pdfA1a_annotationCheckTest08.pdf";
216218
String cmpPdf = cmpFolder + "cmp_pdfA1a_annotationCheckTest08.pdf";
217219

218-
PdfWriter writer = new PdfWriter(outPdf);
220+
PdfWriter writer = new PdfWriter(outPdf, new WriterProperties().setPdfVersion(PdfVersion.PDF_1_4));
219221
InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm");
220222
PdfADocument doc = new PdfADocument(writer, PdfAConformanceLevel.PDF_A_1A, new PdfOutputIntent("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", is));
221223
doc.setTagged();

0 commit comments

Comments
 (0)