@@ -60,7 +60,11 @@ This file is part of the iText (R) project.
6060import com .itextpdf .kernel .exceptions .XrefCycledReferencesException ;
6161import com .itextpdf .kernel .pdf .PdfReader .StrictnessLevel ;
6262import com .itextpdf .kernel .utils .CompareTool ;
63+ import com .itextpdf .kernel .xmp .XMPConst ;
6364import 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 ;
6468import com .itextpdf .test .AssertUtil ;
6569import com .itextpdf .test .ExtendedITextTest ;
6670import com .itextpdf .test .annotations .LogMessage ;
@@ -2298,6 +2302,12 @@ public void getPdfAConformanceLevelPdfDocumentNotReadTest() throws IOException {
22982302 Assert .assertEquals (KernelExceptionMessageConstant .DOCUMENT_HAS_NOT_BEEN_READ_YET , e .getMessage ());
22992303 }
23002304
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+
23012311 @ Test
23022312 public void xrefStreamPointsItselfTest () throws IOException {
23032313 String fileName = SOURCE_FOLDER + "xrefStreamPointsItself.pdf" ;
@@ -2636,6 +2646,26 @@ public void tokensPositionIsNotUpdatedWhileReadingLengthTest() throws IOExceptio
26362646 }
26372647 }
26382648
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+
26392669 private static PdfDictionary getTestPdfDictionary () {
26402670 HashMap <PdfName , PdfObject > tmpMap = new HashMap <PdfName , PdfObject >();
26412671 tmpMap .put (new PdfName ("b" ), new PdfName ("c" ));
@@ -2650,4 +2680,22 @@ private static byte[] createPdfDocumentForTest() throws IOException {
26502680 return baos .toByteArray ();
26512681 }
26522682 }
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+ }
26532701}
0 commit comments