/// <summary>
 /// These functions support parsing serialized RDF into an XMP object, and serailizing an XMP
 /// object into RDF. The input for parsing may be any valid Unicode
 /// encoding. ISO Latin-1 is also recognized, but its use is strongly discouraged. Serialization
 /// is always as UTF-8.
 /// <p/>
 /// <code>parseFromBuffer()</code> parses RDF from an <code>InputStream</code>. The encoding
 /// is recognized automatically.
 /// </summary>
 /// <param name="in">      an <code>InputStream</code> </param>
 /// <param name="options"> Options controlling the parsing.<br>
 ///                The available options are:
 ///                <ul>
 ///                <li> XMP_REQUIRE_XMPMETA - The &lt;x:xmpmeta&gt; XML element is required around
 ///                <tt>&lt;rdf:RDF&gt;</tt>.
 ///                <li> XMP_STRICT_ALIASING - Do not reconcile alias differences, throw an exception.
 ///                </ul>
 ///                <em>Note:</em>The XMP_STRICT_ALIASING option is not yet implemented. </param>
 /// <returns> Returns the <code>XMPMeta</code>-object created from the input. </returns>
 /// <exception cref="XmpException"> If the file is not well-formed XML or if the parsing fails. </exception>
 public static IXmpMeta Parse(Stream @in, ParseOptions options)
 {
     return(XmpMetaParser.Parse(@in, options));
 }
 /// <summary>
 /// Creates an <code>XMPMeta</code>-object from a string.
 /// </summary>
 /// <param name="packet">  a String contain an XMP-file. </param>
 /// <param name="options"> Options controlling the parsing. </param>
 /// <returns> Returns the <code>XMPMeta</code>-object created from the input. </returns>
 /// <exception cref="XmpException"> If the file is not well-formed XML or if the parsing fails. </exception>
 /// <seealso cref= XMPMetaFactory#parseFromString(String, ParseOptions) </seealso>
 public static IXmpMeta ParseFromString(string packet, ParseOptions options)
 {
     return(XmpMetaParser.Parse(packet, options));
 }
 /// <summary>
 /// Creates an <code>XMPMeta</code>-object from a byte-buffer.
 /// </summary>
 /// <param name="buffer">  a String contain an XMP-file. </param>
 /// <param name="options"> Options controlling the parsing. </param>
 /// <returns> Returns the <code>XMPMeta</code>-object created from the input. </returns>
 /// <exception cref="XmpException"> If the file is not well-formed XML or if the parsing fails. </exception>
 /// <seealso cref= XMPMetaFactory#parse(InputStream, ParseOptions) </seealso>
 public static IXmpMeta ParseFromBuffer(byte[] buffer, ParseOptions options)
 {
     return(XmpMetaParser.Parse(buffer, options));
 }
Example #4
0
        private void CheckPdfAInfo(PdfReader reader)
        {
            byte[]       metadata;
            IXmpMeta     xmpMeta;
            IXmpProperty pdfaidConformance;
            IXmpProperty pdfaidPart;

            try {
                metadata          = reader.Metadata;
                xmpMeta           = XmpMetaParser.Parse(metadata, null);
                pdfaidConformance = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:conformance");
                pdfaidPart        = xmpMeta.GetProperty(XmpConst.NS_PDFA_ID, "pdfaid:part");
            } catch (Exception e) {
                throw new PdfAConformanceException(
                          MessageLocalization.GetComposedMessage("only.pdfa.documents.can.be.added.in.PdfACopy"));
            }
            if (pdfaidConformance == null || pdfaidPart == null)
            {
                throw new PdfAConformanceException(
                          MessageLocalization.GetComposedMessage("only.pdfa.documents.can.be.added.in.PdfACopy"));
            }

            switch (((IPdfAConformance)pdfIsoConformance).ConformanceLevel)
            {
            case PdfAConformanceLevel.PDF_A_1A:
            case PdfAConformanceLevel.PDF_A_1B:
                if (!"1".Equals(pdfaidPart.Value))
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("different.pdf.a.version", "1"));
                }
                break;

            case PdfAConformanceLevel.PDF_A_2A:
            case PdfAConformanceLevel.PDF_A_2B:
            case PdfAConformanceLevel.PDF_A_2U:
                if (!"2".Equals(pdfaidPart.Value))
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("different.pdf.a.version", "2"));
                }
                break;

            case PdfAConformanceLevel.PDF_A_3A:
            case PdfAConformanceLevel.PDF_A_3B:
            case PdfAConformanceLevel.PDF_A_3U:
            case PdfAConformanceLevel.ZUGFeRD:
                if (!"3".Equals(pdfaidPart.Value))
                {
                    throw new PdfAConformanceException(MessageLocalization.GetComposedMessage("different.pdf.a.version", "3"));
                }
                break;
            }

            switch (((IPdfAConformance)pdfIsoConformance).ConformanceLevel)
            {
            case PdfAConformanceLevel.PDF_A_1A:
            case PdfAConformanceLevel.PDF_A_2A:
            case PdfAConformanceLevel.PDF_A_3A:
                if (!"A".Equals(pdfaidConformance.Value))
                {
                    throw new PdfAConformanceException(
                              MessageLocalization.GetComposedMessage("incompatible.pdf.a.conformance.level", "a"));
                }
                break;

            case PdfAConformanceLevel.PDF_A_2U:
            case PdfAConformanceLevel.PDF_A_3U:
                if ("B".Equals(pdfaidConformance.Value))
                {
                    throw new PdfAConformanceException(
                              MessageLocalization.GetComposedMessage("incompatible.pdf.a.conformance.level", "u"));
                }
                break;
            }
        }