Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Feb 27, 2024
2 parents 197f407 + 6900571 commit 9096aee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
41 changes: 41 additions & 0 deletions itext.tests/itext.pdfa.tests/itext/pdfa/PdfAXmpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You should have received a copy of the GNU Affero General Public License
*/
using System;
using System.IO;
using iText.IO.Source;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;
using iText.Kernel.XMP;
Expand Down Expand Up @@ -112,6 +113,46 @@ public virtual void SaveAndReadDocumentWithCanonicalXmpMetadata() {
}
}

[NUnit.Framework.Test]
public virtual void TestPdfUAExtensionMetadata() {
String outFile = destinationFolder + "testPdfUAExtensionMetadata.pdf";
String cmpFile = cmpFolder + "cmp_testPdfUAExtensionMetadata.pdf";
using (FileStream fos = new FileStream(outFile, FileMode.Create)) {
GeneratePdfAWithUA(fos);
}
CompareTool ct = new CompareTool();
NUnit.Framework.Assert.IsNull(ct.CompareXmp(outFile, cmpFile, true));
}

[NUnit.Framework.Test]
public virtual void TestPdfUAIdSchemaNameSpaceUriIsNotText() {
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 MemoryStream(baos.ToArray())));
String xmpString = iText.Commons.Utils.JavaUtil.GetStringForBytes(readDoc.GetXmpMetadata(), System.Text.Encoding
.UTF8);
NUnit.Framework.Assert.IsTrue(xmpString.Contains("<pdfaSchema:namespaceURI rdf:resource=\"http://www.aiim.org/pdfua/ns/id/\"/>"
), "Did not find expected namespaceURI definition");
}

private void GeneratePdfAWithUA(Stream os) {
WriterProperties wp = new WriterProperties().AddUAXmpMetadata();
using (PdfWriter w = new PdfWriter(os, wp)) {
PdfOutputIntent outputIntent;
using (Stream @is = new FileStream(sourceFolder + "sRGB Color Space Profile.icm", FileMode.Open, FileAccess.Read
)) {
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;
foreach (byte each in array) {
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion itext/itext.pdfa/itext/pdfa/PdfAXMPUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class PdfAXMPUtil {
public const String PDF_UA_EXTENSION = " <x:xmpmeta xmlns:x=\"adobe:ns:meta/\">\n" + " <rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n"
+ " <rdf:Description rdf:about=\"\" xmlns:pdfaExtension=\"http://www.aiim.org/pdfa/ns/extension/\" xmlns:pdfaSchema=\"http://www.aiim.org/pdfa/ns/schema#\" xmlns:pdfaProperty=\"http://www.aiim.org/pdfa/ns/property#\">\n"
+ " <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" + " <rdf:Seq>\n" + " <rdf:li rdf:parseType=\"Resource\">\n"
+ " <pdfaProperty:category>internal</pdfaProperty:category>\n" + " <pdfaProperty:description>PDF/UA version identifier</pdfaProperty:description>\n"
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5be1eefdbb284bcef7ac9808cbf14bca88b1ec44
123a3d935402746ba9d500b0e13be7c28fd1de2d

0 comments on commit 9096aee

Please sign in to comment.