@@ -60,7 +60,11 @@ This file is part of the iText (R) project.
60
60
import com .itextpdf .kernel .exceptions .XrefCycledReferencesException ;
61
61
import com .itextpdf .kernel .pdf .PdfReader .StrictnessLevel ;
62
62
import com .itextpdf .kernel .utils .CompareTool ;
63
+ import com .itextpdf .kernel .xmp .XMPConst ;
63
64
import com .itextpdf .kernel .xmp .XMPException ;
65
+ import com .itextpdf .kernel .xmp .XMPMeta ;
66
+ import com .itextpdf .kernel .xmp .XMPMetaFactory ;
67
+ import com .itextpdf .kernel .xmp .options .PropertyOptions ;
64
68
import com .itextpdf .test .AssertUtil ;
65
69
import com .itextpdf .test .ExtendedITextTest ;
66
70
import com .itextpdf .test .annotations .LogMessage ;
@@ -2298,6 +2302,12 @@ public void getPdfAConformanceLevelPdfDocumentNotReadTest() throws IOException {
2298
2302
Assert .assertEquals (KernelExceptionMessageConstant .DOCUMENT_HAS_NOT_BEEN_READ_YET , e .getMessage ());
2299
2303
}
2300
2304
2305
+ @ Test
2306
+ public void getPdfAConformanceLevelNoMetadataTest () throws IOException {
2307
+ PdfDocument pdfDoc = new PdfDocument (new PdfReader (new ByteArrayInputStream (createPdfDocumentForTest ())));
2308
+ Assert .assertNull (pdfDoc .getReader ().getPdfAConformanceLevel ());
2309
+ }
2310
+
2301
2311
@ Test
2302
2312
public void xrefStreamPointsItselfTest () throws IOException {
2303
2313
String fileName = SOURCE_FOLDER + "xrefStreamPointsItself.pdf" ;
@@ -2636,6 +2646,26 @@ public void tokensPositionIsNotUpdatedWhileReadingLengthTest() throws IOExceptio
2636
2646
}
2637
2647
}
2638
2648
2649
+ @ Test
2650
+ public void conformanceLevelCacheTest () throws IOException , XMPException {
2651
+ String filename = DESTINATION_FOLDER + "simpleDoc.pdf" ;
2652
+
2653
+ PdfDocument pdfDoc = new PdfDocument (new PdfWriter (filename ));
2654
+ XMPMeta xmp = XMPMetaFactory .create ();
2655
+ xmp .appendArrayItem (XMPConst .NS_DC , "subject" ,
2656
+ new PropertyOptions (PropertyOptions .ARRAY ), "Hello World" , null );
2657
+ pdfDoc .setXmpMetadata (xmp );
2658
+
2659
+ pdfDoc .addNewPage ();
2660
+ pdfDoc .close ();
2661
+
2662
+ TestPdfDocumentCache pdfTestDoc = new TestPdfDocumentCache (new PdfReader (filename ));
2663
+ for (int i = 0 ; i < 1000 ; ++i ) {
2664
+ pdfTestDoc .getReader ().getPdfAConformanceLevel ();
2665
+ }
2666
+ Assert .assertEquals (2 , pdfTestDoc .getCounter ());
2667
+ }
2668
+
2639
2669
private static PdfDictionary getTestPdfDictionary () {
2640
2670
HashMap <PdfName , PdfObject > tmpMap = new HashMap <PdfName , PdfObject >();
2641
2671
tmpMap .put (new PdfName ("b" ), new PdfName ("c" ));
@@ -2650,4 +2680,22 @@ private static byte[] createPdfDocumentForTest() throws IOException {
2650
2680
return baos .toByteArray ();
2651
2681
}
2652
2682
}
2683
+
2684
+ private class TestPdfDocumentCache extends PdfDocument {
2685
+ private int getXmpMetadataCounter ;
2686
+
2687
+ public TestPdfDocumentCache (PdfReader pdfReader ) {
2688
+ super (pdfReader );
2689
+ }
2690
+
2691
+ @ Override
2692
+ public byte [] getXmpMetadata (boolean createNew ) {
2693
+ ++getXmpMetadataCounter ;
2694
+ return super .getXmpMetadata (createNew );
2695
+ }
2696
+
2697
+ public int getCounter () {
2698
+ return getXmpMetadataCounter ;
2699
+ }
2700
+ }
2653
2701
}
0 commit comments