@@ -43,6 +43,8 @@ This file is part of the iText (R) project.
43
43
package com .itextpdf .kernel .pdf ;
44
44
45
45
import com .itextpdf .io .LogMessageConstant ;
46
+ import com .itextpdf .io .util .MessageFormatUtil ;
47
+ import com .itextpdf .kernel .PdfException ;
46
48
import com .itextpdf .kernel .pdf .navigation .PdfDestination ;
47
49
import com .itextpdf .kernel .pdf .navigation .PdfExplicitDestination ;
48
50
import com .itextpdf .kernel .pdf .navigation .PdfStringDestination ;
@@ -52,6 +54,8 @@ This file is part of the iText (R) project.
52
54
import com .itextpdf .test .annotations .LogMessages ;
53
55
import com .itextpdf .test .annotations .type .IntegrationTest ;
54
56
57
+ import java .io .ByteArrayOutputStream ;
58
+ import java .util .HashMap ;
55
59
import org .xml .sax .SAXException ;
56
60
import javax .xml .parsers .ParserConfigurationException ;
57
61
import java .io .FileOutputStream ;
@@ -508,4 +512,56 @@ public void removePageInDocWithComplexOutlineTreeStructTest() throws IOException
508
512
509
513
Assert .assertNull (new CompareTool ().compareByContent (output , cmp , DESTINATION_FOLDER , "diff_" ));
510
514
}
515
+
516
+ @ Test
517
+ public void constructOutlinesNoParentTest () throws IOException {
518
+ try (
519
+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
520
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (baos ))) {
521
+ pdfDocument .addNewPage ();
522
+
523
+ PdfDictionary first = new PdfDictionary ();
524
+ first .makeIndirect (pdfDocument );
525
+
526
+ PdfDictionary outlineDictionary = new PdfDictionary ();
527
+ outlineDictionary .put (PdfName .First , first );
528
+
529
+ Exception exception = Assert .assertThrows (
530
+ PdfException .class ,
531
+ () -> pdfDocument .getCatalog ().constructOutlines (outlineDictionary , new HashMap <String , PdfObject >())
532
+ );
533
+ Assert .assertEquals (
534
+ MessageFormatUtil .format (PdfException .CORRUPTED_OUTLINE_NO_PARENT_ENTRY ,
535
+ first .indirectReference ),
536
+ exception .getMessage ());
537
+ }
538
+ }
539
+
540
+ @ Test
541
+ public void constructOutlinesNoTitleTest () throws IOException {
542
+ try (
543
+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
544
+ PdfDocument pdfDocument = new PdfDocument (new PdfWriter (baos ))) {
545
+ pdfDocument .addNewPage ();
546
+
547
+ PdfDictionary first = new PdfDictionary ();
548
+ first .makeIndirect (pdfDocument );
549
+
550
+ PdfDictionary outlineDictionary = new PdfDictionary ();
551
+ outlineDictionary .makeIndirect (pdfDocument );
552
+
553
+ outlineDictionary .put (PdfName .First , first );
554
+ first .put (PdfName .Parent , outlineDictionary );
555
+
556
+ Exception exception = Assert .assertThrows (
557
+ PdfException .class ,
558
+ () -> pdfDocument .getCatalog ()
559
+ .constructOutlines (outlineDictionary , new HashMap <String , PdfObject >())
560
+ );
561
+ Assert .assertEquals (
562
+ MessageFormatUtil .format (PdfException .CORRUPTED_OUTLINE_NO_TITLE_ENTRY ,
563
+ first .indirectReference ),
564
+ exception .getMessage ());
565
+ }
566
+ }
511
567
}
0 commit comments