@@ -42,11 +42,15 @@ This file is part of the iText (R) project.
4242 */
4343package com .itextpdf .pdfa ;
4444
45+ import com .itextpdf .io .source .ByteArrayOutputStream ;
4546import com .itextpdf .kernel .pdf .PdfAConformanceLevel ;
4647import com .itextpdf .kernel .pdf .PdfDocument ;
4748import com .itextpdf .kernel .pdf .PdfOutputIntent ;
4849import com .itextpdf .kernel .pdf .PdfReader ;
50+ import com .itextpdf .kernel .pdf .PdfString ;
51+ import com .itextpdf .kernel .pdf .PdfViewerPreferences ;
4952import com .itextpdf .kernel .pdf .PdfWriter ;
53+ import com .itextpdf .kernel .pdf .WriterProperties ;
5054import com .itextpdf .kernel .utils .CompareTool ;
5155import com .itextpdf .kernel .xmp .XMPConst ;
5256import com .itextpdf .kernel .xmp .XMPException ;
@@ -56,9 +60,15 @@ This file is part of the iText (R) project.
5660import com .itextpdf .kernel .xmp .options .SerializeOptions ;
5761import com .itextpdf .test .ExtendedITextTest ;
5862import com .itextpdf .test .annotations .type .IntegrationTest ;
63+
64+ import java .io .ByteArrayInputStream ;
5965import java .io .FileInputStream ;
66+ import java .io .FileOutputStream ;
6067import java .io .IOException ;
6168import java .io .InputStream ;
69+ import java .io .OutputStream ;
70+ import java .nio .charset .StandardCharsets ;
71+
6272import org .junit .Assert ;
6373import org .junit .BeforeClass ;
6474import org .junit .Test ;
@@ -147,6 +157,57 @@ public void saveAndReadDocumentWithCanonicalXmpMetadata() throws IOException, XM
147157 }
148158 }
149159
160+ @ Test
161+ public void testPdfUAExtensionMetadata () throws IOException {
162+
163+ String outFile = destinationFolder + "testPdfUAExtensionMetadata.pdf" ;
164+ String cmpFile = cmpFolder + "cmp_testPdfUAExtensionMetadata.pdf" ;
165+
166+ try (FileOutputStream fos = new FileOutputStream (outFile )) {
167+ generatePdfAWithUA (fos );
168+ }
169+
170+ CompareTool ct = new CompareTool ();
171+ Assert .assertNull (ct .compareXmp (outFile , cmpFile , true ));
172+
173+ }
174+
175+ @ Test
176+ public void testPdfUAIdSchemaNameSpaceUriIsNotText () throws IOException {
177+ ByteArrayOutputStream baos = new ByteArrayOutputStream ();
178+ generatePdfAWithUA (baos );
179+
180+ // check whether the pdfuaid NS URI was properly encoded as a URI with rdf:resource
181+ PdfDocument readDoc = new PdfDocument (new PdfReader (new ByteArrayInputStream (baos .toByteArray ())));
182+ String xmpString = new String (readDoc .getXmpMetadata (), StandardCharsets .UTF_8 );
183+ Assert .assertTrue (
184+ "Did not find expected namespaceURI definition" ,
185+ xmpString .contains ("<pdfaSchema:namespaceURI rdf:resource=\" http://www.aiim.org/pdfua/ns/id/\" />" )
186+ );
187+
188+ }
189+
190+ private void generatePdfAWithUA (OutputStream os ) throws IOException {
191+ WriterProperties wp = new WriterProperties ().addUAXmpMetadata ();
192+ try (PdfWriter w = new PdfWriter (os , wp )) {
193+ PdfOutputIntent outputIntent ;
194+ try (InputStream is = new FileInputStream (sourceFolder + "sRGB Color Space Profile.icm" )) {
195+ outputIntent = new PdfOutputIntent (
196+ "Custom" , "" ,
197+ "http://www.color.org" ,
198+ "sRGB IEC61966-2.1" ,
199+ is
200+ );
201+ }
202+ PdfDocument pdfDoc = new PdfADocument (w , PdfAConformanceLevel .PDF_A_2A , outputIntent ).setTagged ();
203+ pdfDoc .getDocumentInfo ().setTitle ("Test document" );
204+ pdfDoc .getCatalog ().setViewerPreferences (new PdfViewerPreferences ().setDisplayDocTitle (true ));
205+ pdfDoc .getCatalog ().setLang (new PdfString ("en" ));
206+ pdfDoc .addNewPage ();
207+ pdfDoc .close ();
208+ }
209+ }
210+
150211 private int count (byte [] array , byte b ) {
151212 int counter = 0 ;
152213 for (byte each : array ) {
0 commit comments