@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
22
22
*/
23
23
package com .itextpdf .layout ;
24
24
25
+ import com .itextpdf .commons .datastructures .Tuple2 ;
25
26
import com .itextpdf .commons .utils .MessageFormatUtil ;
26
27
import com .itextpdf .kernel .colors .ColorConstants ;
27
28
import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
@@ -36,7 +37,9 @@ This file is part of the iText (R) project.
36
37
import com .itextpdf .kernel .pdf .PdfDocumentInfo ;
37
38
import com .itextpdf .kernel .pdf .PdfName ;
38
39
import com .itextpdf .kernel .pdf .PdfNumber ;
40
+ import com .itextpdf .kernel .pdf .PdfOutline ;
39
41
import com .itextpdf .kernel .pdf .PdfPage ;
42
+ import com .itextpdf .kernel .pdf .PdfReader ;
40
43
import com .itextpdf .kernel .pdf .PdfString ;
41
44
import com .itextpdf .kernel .pdf .PdfVersion ;
42
45
import com .itextpdf .kernel .pdf .PdfViewerPreferences ;
@@ -67,6 +70,7 @@ This file is part of the iText (R) project.
67
70
import com .itextpdf .layout .element .Text ;
68
71
import com .itextpdf .layout .properties .HorizontalAlignment ;
69
72
import com .itextpdf .layout .properties .ListNumberingType ;
73
+ import com .itextpdf .layout .properties .Property ;
70
74
import com .itextpdf .test .ExtendedITextTest ;
71
75
import com .itextpdf .test .annotations .type .IntegrationTest ;
72
76
import com .itextpdf .test .pdfa .VeraPdfValidator ; // Android-Conversion-Skip-Line (TODO DEVSIX-7377 introduce pdf\a validation on Android)
@@ -724,7 +728,8 @@ public void checkStructureDestinationTest() throws IOException, InterruptedExcep
724
728
String outFile = DESTINATION_FOLDER + "structureDestination01Test.pdf" ;
725
729
String cmpFile = SOURCE_FOLDER + "cmp_structureDestination01Test.pdf" ;
726
730
727
- try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile , new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
731
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile ,
732
+ new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
728
733
Document document = new Document (pdfDocument );
729
734
PdfFont font = PdfFontFactory .createFont (FONT_FOLDER + "FreeSans.ttf" ,
730
735
"WinAnsi" , EmbeddingStrategy .FORCE_EMBEDDED );
@@ -756,6 +761,52 @@ public void checkStructureDestinationTest() throws IOException, InterruptedExcep
756
761
compareAndValidate (outFile , cmpFile );
757
762
}
758
763
764
+ @ Test
765
+ public void checkOutlinesAsStructureDestinationsTest () throws IOException , XMPException , InterruptedException {
766
+ String outFile = DESTINATION_FOLDER + "checkOutlinesAsStructureDestinations.pdf" ;
767
+ String cmpFile = SOURCE_FOLDER + "cmp_checkOutlinesAsStructureDestinations.pdf" ;
768
+
769
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfWriter (outFile ,
770
+ new WriterProperties ().setPdfVersion (PdfVersion .PDF_2_0 )))) {
771
+ Document document = new Document (pdfDocument );
772
+ PdfFont font = PdfFontFactory .createFont (FONT_FOLDER + "FreeSans.ttf" ,
773
+ "WinAnsi" , EmbeddingStrategy .FORCE_EMBEDDED );
774
+ document .setFont (font );
775
+
776
+ createSimplePdfUA2Document (pdfDocument );
777
+
778
+ PdfOutline topOutline = pdfDocument .getOutlines (false );
779
+ PdfOutline header1Outline = topOutline .addOutline ("header1 title" );
780
+ PdfAction action1 = PdfAction .createGoTo ("header1" );
781
+ header1Outline .addAction (action1 );
782
+
783
+ PdfOutline header11Outline = header1Outline .addOutline ("header1.1 title" );
784
+ PdfAction action11 = PdfAction .createGoTo ("header1.1" );
785
+ header11Outline .addAction (action11 );
786
+
787
+
788
+ Paragraph header1 = new Paragraph ("header1 text" );
789
+ header1 .setProperty (Property .DESTINATION ,
790
+ new Tuple2 <String , PdfDictionary >("header1" , action1 .getPdfObject ()));
791
+ Paragraph header11 = new Paragraph ("header1.1 text" );
792
+ header11 .setProperty (Property .DESTINATION ,
793
+ new Tuple2 <String , PdfDictionary >("header1.1" , action11 .getPdfObject ()));
794
+
795
+ document .add (header1 );
796
+ document .add (header11 );
797
+ }
798
+
799
+ compareAndValidate (outFile , cmpFile );
800
+
801
+ try (PdfDocument pdfDocument = new PdfDocument (new PdfReader (outFile ))) {
802
+ PdfOutline outline = pdfDocument .getOutlines (false );
803
+ Assert .assertEquals ("header1" , outline .getAllChildren ().get (0 )
804
+ .getDestination ().getPdfObject ().toString ());
805
+ Assert .assertEquals ("header1.1" , outline .getAllChildren ().get (0 ).getAllChildren ().get (0 )
806
+ .getDestination ().getPdfObject ().toString ());
807
+ }
808
+ }
809
+
759
810
private void createSimplePdfUA2Document (PdfDocument pdfDocument ) throws IOException , XMPException {
760
811
byte [] bytes = Files .readAllBytes (Paths .get (SOURCE_FOLDER + "simplePdfUA2.xmp" ));
761
812
XMPMeta xmpMeta = XMPMetaFactory .parse (new ByteArrayInputStream (bytes ));
0 commit comments