Skip to content

Commit 26bed2b

Browse files
committed
Add some link tests.
The test demonstrates that the annotation's rectangle isn't considered while rendering a Link layout element. DEVSIX-3150
1 parent 67c7759 commit 26bed2b

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ This file is part of the iText (R) project.
4444

4545
import com.itextpdf.io.LogMessageConstant;
4646
import com.itextpdf.kernel.colors.ColorConstants;
47+
import com.itextpdf.kernel.geom.Rectangle;
4748
import com.itextpdf.kernel.pdf.PdfArray;
4849
import com.itextpdf.kernel.pdf.PdfDocument;
4950
import com.itextpdf.kernel.pdf.PdfName;
5051
import com.itextpdf.kernel.pdf.PdfNumber;
5152
import com.itextpdf.kernel.pdf.PdfWriter;
5253
import com.itextpdf.kernel.pdf.action.PdfAction;
54+
import com.itextpdf.kernel.pdf.annot.PdfLinkAnnotation;
5355
import com.itextpdf.kernel.pdf.navigation.PdfDestination;
5456
import com.itextpdf.kernel.pdf.navigation.PdfExplicitDestination;
5557
import com.itextpdf.kernel.utils.CompareTool;
@@ -305,7 +307,34 @@ public void tableHeaderLinkTest01() throws IOException, InterruptedException {
305307
doc.close();
306308

307309
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder, "diff"));
308-
309310
}
310311

312+
@Test
313+
public void linkWithCustomRectangleTest01() throws IOException, InterruptedException {
314+
String outFileName = destinationFolder + "linkWithCustomRectangleTest01.pdf";
315+
String cmpFileName = sourceFolder + "cmp_linkWithCustomRectangleTest01.pdf";
316+
317+
PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outFileName));
318+
Document doc = new Document(pdfDocument);
319+
320+
String text = "Hello World";
321+
322+
PdfAction action = PdfAction.createURI("http://itextpdf.com");
323+
324+
PdfLinkAnnotation annotation = new PdfLinkAnnotation(new Rectangle(1, 1)).setAction(action);
325+
326+
Link linkByAnnotation = new Link(text, annotation);
327+
doc.add(new Paragraph(linkByAnnotation));
328+
329+
annotation.setRectangle(new PdfArray(new Rectangle(100, 100, 20, 20)));
330+
Link linkByChangedAnnotation = new Link(text, annotation);
331+
doc.add(new Paragraph(linkByChangedAnnotation));
332+
333+
Link linkByAction = new Link(text, action);
334+
doc.add(new Paragraph(linkByAction));
335+
336+
doc.close();
337+
338+
Assert.assertNull(new CompareTool().compareByContent(outFileName, cmpFileName, destinationFolder));
339+
}
311340
}

0 commit comments

Comments
 (0)