@@ -22,6 +22,7 @@ This file is part of the iText (R) project.
2222 */
2323package com .itextpdf .layout ;
2424
25+ import com .itextpdf .commons .datastructures .Tuple2 ;
2526import com .itextpdf .commons .utils .MessageFormatUtil ;
2627import com .itextpdf .kernel .colors .ColorConstants ;
2728import com .itextpdf .kernel .exceptions .KernelExceptionMessageConstant ;
@@ -36,7 +37,9 @@ This file is part of the iText (R) project.
3637import com .itextpdf .kernel .pdf .PdfDocumentInfo ;
3738import com .itextpdf .kernel .pdf .PdfName ;
3839import com .itextpdf .kernel .pdf .PdfNumber ;
40+ import com .itextpdf .kernel .pdf .PdfOutline ;
3941import com .itextpdf .kernel .pdf .PdfPage ;
42+ import com .itextpdf .kernel .pdf .PdfReader ;
4043import com .itextpdf .kernel .pdf .PdfString ;
4144import com .itextpdf .kernel .pdf .PdfVersion ;
4245import com .itextpdf .kernel .pdf .PdfViewerPreferences ;
@@ -67,6 +70,7 @@ This file is part of the iText (R) project.
6770import com .itextpdf .layout .element .Text ;
6871import com .itextpdf .layout .properties .HorizontalAlignment ;
6972import com .itextpdf .layout .properties .ListNumberingType ;
73+ import com .itextpdf .layout .properties .Property ;
7074import com .itextpdf .test .ExtendedITextTest ;
7175import com .itextpdf .test .annotations .type .IntegrationTest ;
7276import 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
724728 String outFile = DESTINATION_FOLDER + "structureDestination01Test.pdf" ;
725729 String cmpFile = SOURCE_FOLDER + "cmp_structureDestination01Test.pdf" ;
726730
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 )))) {
728733 Document document = new Document (pdfDocument );
729734 PdfFont font = PdfFontFactory .createFont (FONT_FOLDER + "FreeSans.ttf" ,
730735 "WinAnsi" , EmbeddingStrategy .FORCE_EMBEDDED );
@@ -756,6 +761,52 @@ public void checkStructureDestinationTest() throws IOException, InterruptedExcep
756761 compareAndValidate (outFile , cmpFile );
757762 }
758763
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+
759810 private void createSimplePdfUA2Document (PdfDocument pdfDocument ) throws IOException , XMPException {
760811 byte [] bytes = Files .readAllBytes (Paths .get (SOURCE_FOLDER + "simplePdfUA2.xmp" ));
761812 XMPMeta xmpMeta = XMPMetaFactory .parse (new ByteArrayInputStream (bytes ));
0 commit comments