private static void Metadata(MagickImage image, ImageDetails details) { var xmp = MetadataController.Get(details); var xmpBuffer = XmpMetaFactory.SerializeToBuffer(xmp, new SerializeOptions()); var xmpProfile = new XmpProfile(xmpBuffer); image.AddProfile(xmpProfile); var iptcProfile = new IptcProfile(); iptcProfile.SetValue(IptcTag.City, "London"); iptcProfile.SetValue(IptcTag.Country, "UK"); iptcProfile.SetValue(IptcTag.Contact, "[email protected], +447740424810,http://www.mcandrewphoto.co.uk"); iptcProfile.SetValue(IptcTag.CopyrightNotice, "Attribution 3.0 Unported (CC BY 3.0)"); iptcProfile.SetValue(IptcTag.Title, $"{details.GivenName} {details.FamilyName}"); iptcProfile.SetValue(IptcTag.Source, "Chris McAndrew / UK Parliament"); iptcProfile.SetValue(IptcTag.Credit, "Chris McAndrew / UK Parliament (Attribution 3.0 Unported (CC BY 3.0))"); image.AddProfile(iptcProfile); }
private void CompareResults(String orig, String curr) { PdfReader cmpReader = new PdfReader(CMP_FOLDER + orig); PdfReader outReader = new PdfReader(OUT_FOLDER + curr); byte[] cmpBytes = cmpReader.Metadata, outBytes = outReader.Metadata; IXmpMeta xmpMeta = XmpMetaFactory.ParseFromBuffer(cmpBytes); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_XMP, XmpBasicProperties.CREATEDATE, true, true); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_XMP, XmpBasicProperties.MODIFYDATE, true, true); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_XMP, XmpBasicProperties.METADATADATE, true, true); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_PDF, PdfProperties.PRODUCER, true, true); cmpBytes = XmpMetaFactory.SerializeToBuffer(xmpMeta, new SerializeOptions(SerializeOptions.SORT)); xmpMeta = XmpMetaFactory.ParseFromBuffer(outBytes); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_XMP, XmpBasicProperties.CREATEDATE, true, true); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_XMP, XmpBasicProperties.MODIFYDATE, true, true); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_XMP, XmpBasicProperties.METADATADATE, true, true); XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_PDF, PdfProperties.PRODUCER, true, true); outBytes = XmpMetaFactory.SerializeToBuffer(xmpMeta, new SerializeOptions(SerializeOptions.SORT)); XmlDiff xmldiff = new XmlDiff(XmlDiffOptions.None); if (!xmldiff.Compare(new XmlTextReader(new MemoryStream(cmpBytes)), new XmlTextReader(new MemoryStream(outBytes)))) { String currXmlName = curr.Replace(".pdf", ".xml"); FileStream outStream = new FileStream(OUT_FOLDER + "cmp_" + currXmlName, FileMode.Create); outStream.Write(cmpBytes, 0, cmpBytes.Length); outStream = new FileStream(OUT_FOLDER + currXmlName, FileMode.Create); outStream.Write(outBytes, 0, outBytes.Length); Assert.Fail("The XMP packages are different!"); } }
/** * Covers the serialization of an <code>XmpMeta</code> object with different options. * @throws Exception Forwards exceptions */ private static void CoverSerialization() { writeMajorLabel("Test serialization with various options"); var meta = XmpMetaFactory.ParseFromString(TestData.SIMPLE_RDF); meta.SetProperty(TestData.NS2, "Another", "Something in another schema"); meta.SetProperty(TestData.NS2, "Yet/pdf:More", "Yet more in another schema"); printXmpMeta(meta, "Parse simple RDF, serialize with various options"); writeMinorLabel("Default serialize"); log.WriteLine(XmpMetaFactory.SerializeToString(meta, null)); writeMinorLabel("Compact RDF, no packet serialize"); log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions { UseCompactFormat = true, OmitPacketWrapper = true })); writeMinorLabel("Read-only serialize"); log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions { ReadOnlyPacket = true })); writeMinorLabel("Alternate newline serialize"); log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions { Newline = "<--newline-->\n", OmitPacketWrapper = true })); writeMinorLabel("Alternate indent serialize"); log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions { Indent = "-->", BaseIndent = 5, OmitPacketWrapper = true })); writeMinorLabel("Small padding serialize"); log.WriteLine(XmpMetaFactory.SerializeToString(meta, new SerializeOptions { Padding = 10 })); writeMinorLabel("Serialize with exact packet size"); int s = XmpMetaFactory.SerializeToBuffer(meta, new SerializeOptions { ReadOnlyPacket = true }).Length; log.WriteLine("Minimum packet size is " + s + " bytes\n"); // with the flag "exact packet size" the padding becomes the overall length of the packet byte[] buffer = XmpMetaFactory.SerializeToBuffer(meta, new SerializeOptions { ExactPacketLength = true, Padding = s }); log.WriteLine(Encoding.UTF8.GetString(buffer, 0, buffer.Length)); try { XmpMetaFactory.ParseFromString(XmpMetaFactory.SerializeToString(meta, new SerializeOptions { ExactPacketLength = true, Padding = s - 1 })); } catch (XmpException e) { log.WriteLine("\nExact packet size smaller than minimal packet length - threw XmpException #{0} : {1}", e.GetErrorCode(), e.Message); } }