Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdfa/src/main/java/com/itextpdf/pdfa/PdfAXMPUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class PdfAXMPUtil {
" <pdfaExtension:schemas>\n" +
" <rdf:Bag>\n" +
" <rdf:li rdf:parseType=\"Resource\">\n" +
" <pdfaSchema:namespaceURI>http://www.aiim.org/pdfua/ns/id/</pdfaSchema:namespaceURI>\n" +
" <pdfaSchema:namespaceURI rdf:resource=\"http://www.aiim.org/pdfua/ns/id/\"/>\n" +
" <pdfaSchema:prefix>pdfuaid</pdfaSchema:prefix>\n" +
" <pdfaSchema:schema>PDF/UA identification schema</pdfaSchema:schema>\n" +
" <pdfaSchema:property>\n" +
Expand Down
61 changes: 61 additions & 0 deletions pdfa/src/test/java/com/itextpdf/pdfa/PdfAXmpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ This file is part of the iText (R) project.
*/
package com.itextpdf.pdfa;

import com.itextpdf.io.source.ByteArrayOutputStream;
import com.itextpdf.kernel.pdf.PdfAConformanceLevel;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfOutputIntent;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfString;
import com.itextpdf.kernel.pdf.PdfViewerPreferences;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.WriterProperties;
import com.itextpdf.kernel.utils.CompareTool;
import com.itextpdf.kernel.xmp.XMPConst;
import com.itextpdf.kernel.xmp.XMPException;
Expand All @@ -56,9 +60,15 @@ This file is part of the iText (R) project.
import com.itextpdf.kernel.xmp.options.SerializeOptions;
import com.itextpdf.test.ExtendedITextTest;
import com.itextpdf.test.annotations.type.IntegrationTest;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
Expand Down Expand Up @@ -147,6 +157,57 @@ public void saveAndReadDocumentWithCanonicalXmpMetadata() throws IOException, XM
}
}

@Test
public void testPdfUAExtensionMetadata() throws IOException {

String outFile = destinationFolder + "testPdfUAExtensionMetadata.pdf";
String cmpFile = cmpFolder + "cmp_testPdfUAExtensionMetadata.pdf";

try (FileOutputStream fos = new FileOutputStream(outFile)) {
generatePdfAWithUA(fos);
}

CompareTool ct = new CompareTool();
Assert.assertNull(ct.compareXmp(outFile, cmpFile, true));

}

@Test
public void testPdfUAIdSchemaNameSpaceUriIsNotText() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
generatePdfAWithUA(baos);

// check whether the pdfuaid NS URI was properly encoded as a URI with rdf:resource
PdfDocument readDoc = new PdfDocument(new PdfReader(new ByteArrayInputStream(baos.toByteArray())));
String xmpString = new String(readDoc.getXmpMetadata(), StandardCharsets.UTF_8);
Assert.assertTrue(
"Did not find expected namespaceURI definition",
xmpString.contains("<pdfaSchema:namespaceURI rdf:resource=\"http://www.aiim.org/pdfua/ns/id/\"/>")
);

}

private void generatePdfAWithUA(OutputStream os) throws IOException {
WriterProperties wp = new WriterProperties().addUAXmpMetadata();
try (PdfWriter w = new PdfWriter(os, wp)) {
PdfOutputIntent outputIntent;
try (InputStream is = new FileInputStream(sourceFolder + "sRGB Color Space Profile.icm")) {
outputIntent = new PdfOutputIntent(
"Custom", "",
"http://www.color.org",
"sRGB IEC61966-2.1",
is
);
}
PdfDocument pdfDoc = new PdfADocument(w, PdfAConformanceLevel.PDF_A_2A, outputIntent).setTagged();
pdfDoc.getDocumentInfo().setTitle("Test document");
pdfDoc.getCatalog().setViewerPreferences(new PdfViewerPreferences().setDisplayDocTitle(true));
pdfDoc.getCatalog().setLang(new PdfString("en"));
pdfDoc.addNewPage();
pdfDoc.close();
}
}

private int count(byte[] array, byte b) {
int counter = 0;
for (byte each : array) {
Expand Down
Binary file not shown.