@@ -44,12 +44,14 @@ This file is part of the iText (R) project.
44
44
45
45
import com .itextpdf .io .LogMessageConstant ;
46
46
import com .itextpdf .kernel .colors .ColorConstants ;
47
+ import com .itextpdf .kernel .geom .Rectangle ;
47
48
import com .itextpdf .kernel .pdf .PdfArray ;
48
49
import com .itextpdf .kernel .pdf .PdfDocument ;
49
50
import com .itextpdf .kernel .pdf .PdfName ;
50
51
import com .itextpdf .kernel .pdf .PdfNumber ;
51
52
import com .itextpdf .kernel .pdf .PdfWriter ;
52
53
import com .itextpdf .kernel .pdf .action .PdfAction ;
54
+ import com .itextpdf .kernel .pdf .annot .PdfLinkAnnotation ;
53
55
import com .itextpdf .kernel .pdf .navigation .PdfDestination ;
54
56
import com .itextpdf .kernel .pdf .navigation .PdfExplicitDestination ;
55
57
import com .itextpdf .kernel .utils .CompareTool ;
@@ -305,7 +307,34 @@ public void tableHeaderLinkTest01() throws IOException, InterruptedException {
305
307
doc .close ();
306
308
307
309
Assert .assertNull (new CompareTool ().compareByContent (outFileName , cmpFileName , destinationFolder , "diff" ));
308
-
309
310
}
310
311
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
+ }
311
340
}
0 commit comments