virtual public void DeprecatedLogicTest() { String fileName = "xmp_metadata_deprecated.pdf"; // step 1 Document document = new Document(); // step 2 PdfWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create), PdfAConformanceLevel.PDF_A_2B); MemoryStream os = new MemoryStream(); XmpWriter xmp = new PdfAXmpWriter(os, PdfAConformanceLevel.PDF_A_2B, writer); XmpSchema dc = new DublinCoreSchema(); XmpArray subject = new XmpArray(XmpArray.UNORDERED); subject.Add("Hello World"); subject.Add("XMP & Metadata"); subject.Add("Metadata"); dc.SetProperty(DublinCoreSchema.SUBJECT, subject); xmp.AddRdfDescription(dc.Xmlns, dc.ToString()); PdfSchema pdf = new PdfSchema(); pdf.AddKeywords("Hello World, XMP & Metadata, Metadata"); pdf.AddVersion("1.4"); xmp.AddRdfDescription(pdf); xmp.Close(); writer.XmpMetadata = os.ToArray(); // step 3 document.Open(); document.AddLanguage("en_US"); // step 4 Font font = FontFactory.GetFont("../../resources/text/pdfa/FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12); document.Add(new Paragraph("Hello World", font)); FileStream iccStream = new FileStream("../../resources/text/pdfa/sRGB Color Space Profile.icm", FileMode.Open); ICC_Profile icc = ICC_Profile.GetInstance(iccStream); iccStream.Close(); writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); // step 5 document.Close(); CompareResults("xmp_metadata_deprecated.pdf", fileName); }
virtual public void ManipulatePdf2Test() { String fileName = "xmp_metadata_added2.pdf"; PdfReader reader = new PdfReader(CMP_FOLDER + "pdf_metadata.pdf"); PdfStamper stamper = new PdfAStamper(reader, new FileStream(OUT_FOLDER + fileName, FileMode.Create), PdfAConformanceLevel.PDF_A_1A); MemoryStream os = new MemoryStream(); XmpWriter xmp = new PdfAXmpWriter(os, reader.Info, PdfAConformanceLevel.PDF_A_1A, stamper.Writer); DublinCoreProperties.AddSubject(xmp.XmpMeta, "Hello World"); DublinCoreProperties.AddSubject(xmp.XmpMeta, "XMP & Metadata"); DublinCoreProperties.AddSubject(xmp.XmpMeta, "Metadata"); PdfProperties.SetVersion(xmp.XmpMeta, "1.4"); xmp.Close(); stamper.XmpMetadata = os.ToArray(); stamper.Close(); reader.Close(); CompareResults(fileName, fileName); }
virtual public void XmpEncodingTest() { String fileName = "xmp_utf-8_encoding"; Document document = new Document(); PdfSmartCopy copy = new PdfSmartCopy(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create)); document.Open(); PdfReader reader = new PdfReader(CMP_FOLDER + "pdf_metadata.pdf"); int pageCount = reader.NumberOfPages; for (int currentPage = 1; currentPage <= pageCount; currentPage++) { PdfImportedPage page = copy.GetImportedPage(reader, currentPage); copy.AddPage(page); } PdfAConformanceLevel pdfaLevel = PdfAConformanceLevel.PDF_A_1B; MemoryStream os = new MemoryStream(); PdfAXmpWriter xmp = new PdfAXmpWriter(os, copy.Info, pdfaLevel, copy); xmp.Close(); copy.XmpMetadata = os.ToArray(); string metadataXml = System.Text.Encoding.GetEncoding("UTF-8").GetString(copy.XmpMetadata); XmlDocument doc = new XmlDocument(); doc.LoadXml(metadataXml); //<-- This is where the exception is thrown document.Close(); copy.Close(); reader.Close(); }
virtual public void XmpEncodingTest() { String fileName = "xmp_utf-8_encoding"; Document document = new Document(); PdfSmartCopy copy = new PdfSmartCopy(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create)); document.Open(); PdfReader reader = new PdfReader(CMP_FOLDER + "pdf_metadata.pdf"); int pageCount = reader.NumberOfPages; for (int currentPage = 1; currentPage <= pageCount; currentPage++) { PdfImportedPage page = copy.GetImportedPage(reader, currentPage); copy.AddPage(page); } PdfAConformanceLevel pdfaLevel = PdfAConformanceLevel.PDF_A_1B; MemoryStream os = new MemoryStream(); PdfAXmpWriter xmp = new PdfAXmpWriter(os, copy.Info, pdfaLevel, copy); xmp.Close(); copy.XmpMetadata = os.ToArray(); string metadataXml = System.Text.Encoding.GetEncoding("UTF-8").GetString(copy.XmpMetadata); XmlDocument doc = new XmlDocument(); doc.LoadXml(metadataXml); //<-- This is where the exception is thrown document.Close(); copy.Close(); reader.Close(); }
virtual public void DeprecatedLogicTest() { String fileName = "xmp_metadata_deprecated.pdf"; // step 1 Document document = new Document(); // step 2 PdfWriter writer = PdfAWriter.GetInstance(document, new FileStream(OUT_FOLDER + fileName, FileMode.Create), PdfAConformanceLevel.PDF_A_2B); MemoryStream os = new MemoryStream(); XmpWriter xmp = new PdfAXmpWriter(os, PdfAConformanceLevel.PDF_A_2B, writer); XmpSchema dc = new DublinCoreSchema(); XmpArray subject = new XmpArray(XmpArray.UNORDERED); subject.Add("Hello World"); subject.Add("XMP & Metadata"); subject.Add("Metadata"); dc.SetProperty(DublinCoreSchema.SUBJECT, subject); xmp.AddRdfDescription(dc.Xmlns, dc.ToString()); PdfSchema pdf = new PdfSchema(); pdf.AddKeywords("Hello World, XMP & Metadata, Metadata"); pdf.AddVersion("1.4"); xmp.AddRdfDescription(pdf); xmp.Close(); writer.XmpMetadata = os.ToArray(); // step 3 document.Open(); document.AddLanguage("en_US"); // step 4 Font font = FontFactory.GetFont("../../resources/text/pdfa/FreeMonoBold.ttf", BaseFont.WINANSI, BaseFont.EMBEDDED, 12); document.Add(new Paragraph("Hello World", font)); FileStream iccStream = new FileStream("../../resources/text/pdfa/sRGB Color Space Profile.icm", FileMode.Open); ICC_Profile icc = ICC_Profile.GetInstance(iccStream); iccStream.Close(); writer.SetOutputIntents("Custom", "", "http://www.color.org", "sRGB IEC61966-2.1", icc); // step 5 document.Close(); CompareResults("xmp_metadata_deprecated.pdf", fileName); }
virtual public void ManipulatePdf2Test() { String fileName = "xmp_metadata_added2.pdf"; PdfReader reader = new PdfReader(CMP_FOLDER + "pdf_metadata.pdf"); PdfStamper stamper = new PdfAStamper(reader, new FileStream(OUT_FOLDER + fileName, FileMode.Create), PdfAConformanceLevel.PDF_A_1A); MemoryStream os = new MemoryStream(); XmpWriter xmp = new PdfAXmpWriter(os, reader.Info, PdfAConformanceLevel.PDF_A_1A, stamper.Writer); DublinCoreProperties.AddSubject(xmp.XmpMeta, "Hello World"); DublinCoreProperties.AddSubject(xmp.XmpMeta, "XMP & Metadata"); DublinCoreProperties.AddSubject(xmp.XmpMeta, "Metadata"); PdfProperties.SetVersion(xmp.XmpMeta, "1.4"); xmp.Close(); stamper.XmpMetadata = os.ToArray(); stamper.Close(); reader.Close(); CompareResults(fileName, fileName); }