Exemplo n.º 1
0
        /**
         * Adds information about the PDF/A conformance level to the XMP metadata.
         *
         * @param conformanceLevel
         * @throws IOException
         */
        private void AddRdfDescription(PdfAConformanceLevel conformanceLevel)
        {
            switch (conformanceLevel)
            {
            case PdfAConformanceLevel.PDF_A_1A:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "1");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "A");
                break;

            case PdfAConformanceLevel.PDF_A_1B:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "1");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "B");
                break;

            case PdfAConformanceLevel.PDF_A_2A:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "2");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "A");
                break;

            case PdfAConformanceLevel.PDF_A_2B:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "2");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "B");
                break;

            case PdfAConformanceLevel.PDF_A_2U:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "2");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "U");
                break;

            case PdfAConformanceLevel.PDF_A_3A:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "3");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "A");
                break;

            case PdfAConformanceLevel.PDF_A_3B:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "3");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "B");
                break;

            case PdfAConformanceLevel.PDF_A_3U:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "3");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "U");
                break;

            case PdfAConformanceLevel.ZUGFeRD:
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.PART, "3");
                xmpMeta.SetProperty(XmpConst.NS_PDFA_ID, PdfAProperties.CONFORMANCE, "B");
                IXmpMeta taggedExtensionMeta = XmpMetaFactory.ParseFromString(zugferdExtension);
                XmpUtils.AppendProperties(taggedExtensionMeta, xmpMeta, true, false);
                break;

            default:
                break;
            }
            if (writer.IsTagged())
            {
                IXmpMeta taggedExtensionMeta = XmpMetaFactory.ParseFromString(pdfUaExtension);
                XmpUtils.AppendProperties(taggedExtensionMeta, xmpMeta, true, false);
            }
        }
Exemplo n.º 2
0
        /** Sets the identifier.
         *
         * @param xmpMeta
         * @param id
         */

        public static void SetIdentifiers(IXmpMeta xmpMeta, String[] id)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, IDENTIFIER, true, true);
            for (int i = 0; i < id.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, IDENTIFIER, new PropertyOptions(PropertyOptions.ARRAY), id[i],
                                        null);
            }
        }
Exemplo n.º 3
0
        /**
         * Sets an array of publishers.
         *
         * @param xmpMeta
         * @param publisher
         */

        public static void SetPublisher(IXmpMeta xmpMeta, String[] publisher)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, PUBLISHER, true, true);
            for (int i = 0; i < publisher.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, PUBLISHER, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                        publisher[i], null);
            }
        }
Exemplo n.º 4
0
        /**
         * Sets an array of authors.
         *
         * @param xmpMeta
         * @param author
         */

        public static void SetAuthor(IXmpMeta xmpMeta, String[] author)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, CREATOR, true, true);
            for (int i = 0; i < author.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, CREATOR, new PropertyOptions(PropertyOptions.ARRAY_ORDERED),
                                        author[i], null);
            }
        }
Exemplo n.º 5
0
        /**
         * Sets a subject.
         *
         * @param xmpMeta
         * @param subject array of subjects
         */

        public static void SetSubject(IXmpMeta xmpMeta, String[] subject)
        {
            XmpUtils.RemoveProperties(xmpMeta, XmpConst.NS_DC, SUBJECT, true, true);
            for (int i = 0; i < subject.Length; i++)
            {
                xmpMeta.AppendArrayItem(XmpConst.NS_DC, SUBJECT, new PropertyOptions(PropertyOptions.ARRAY), subject[i],
                                        null);
            }
        }
Exemplo n.º 6
0
        public void PackageEmptyXmpDataToJPEG()
        {
            IXmpMeta      data     = new XmpMeta();
            StringBuilder standard = new StringBuilder();
            StringBuilder extended = new StringBuilder();
            StringBuilder digest   = new StringBuilder();

            XmpUtils.PackageForJPEG(data, standard, extended, digest);

            Assert.Equal(0, extended.Length);
        }
Exemplo n.º 7
0
        public void ConvertToInteger()
        {
            Assert.Equal(1, XmpUtils.ConvertToInteger("1"));
            Assert.Equal(1, XmpUtils.ConvertToInteger("001"));
            Assert.Equal(1, XmpUtils.ConvertToInteger("0x1"));
            Assert.Equal(15, XmpUtils.ConvertToInteger("0xF"));
            Assert.Equal(-1, XmpUtils.ConvertToInteger("-1"));
            Assert.Equal(123, XmpUtils.ConvertToInteger(" 123 "));

            Assert.Throws <XmpException>(() => XmpUtils.ConvertToInteger(null));
            Assert.Throws <XmpException>(() => XmpUtils.ConvertToInteger("Foo"));
        }
Exemplo n.º 8
0
        public void ConvertToLong()
        {
            Assert.Equal(1L, XmpUtils.ConvertToLong("1"));
            Assert.Equal(1L, XmpUtils.ConvertToLong("001"));
            Assert.Equal(1L, XmpUtils.ConvertToLong("0x1"));
            Assert.Equal(15L, XmpUtils.ConvertToLong("0xF"));
            Assert.Equal(-1L, XmpUtils.ConvertToLong("-1"));
            Assert.Equal(123L, XmpUtils.ConvertToLong(" 123 "));

            Assert.Throws <XmpException>(() => XmpUtils.ConvertToLong(null));
            Assert.Throws <XmpException>(() => XmpUtils.ConvertToLong("Foo"));
        }
Exemplo n.º 9
0
        private void GenerateEAttachmentDocument(PdfAWriter writer, XmpWriter xmpWriter, EAttactment attachment)
        {
            // Use default intent if output intent of this instance was not set
            if (attachment.outputIntents == null)
            {
                //byte[] iccProfile = File.ReadAllBytes("/Resources/sRGB Color Space Profile.icm");
                byte[]      iccProfile = Properties.Resources.sRGB_Color_Space_Profile;
                ICC_Profile icc        = ICC_Profile.GetInstance(iccProfile);
                writer.SetOutputIntents("sRGB IEC61966-2.1", "", "http://www.color.org", "sRGB IEC61966-2.1", icc);
            }
            else
            {
                OutputIntents outputIntents       = attachment.outputIntents;
                byte[]        iccProfileByteArray = File.ReadAllBytes(outputIntents.colorProfilePath);
                ICC_Profile   icc = ICC_Profile.GetInstance(iccProfileByteArray);
                writer.SetOutputIntents(outputIntents.outputConditionIdentifier, outputIntents.outputCondition, outputIntents.registryName, outputIntents.info, icc);
            }

            //============= Create Exchange ECertificate =================
            // 1 add ContentInformation.xml to document
            PdfArray attachmentArray = new PdfArray();

            writer.ExtraCatalog.Put(new PdfName("AF"), attachmentArray);
            PdfFileSpecification contentSpec = this.EmbeddedAttachment(attachment.contentInformationXMLPath, attachment.attachmentName,
                                                                       attachment.attachmentMIME, new PdfName(attachment.attachmentType), writer, attachment.attachmentDescription);

            attachmentArray.Add(contentSpec.Reference);

            foreach (var item in attachment.fileAttachments)
            {
                contentSpec = this.EmbeddedAttachment(item.attachmentPath, item.attachmentName,
                                                      item.attachmentMIME, new PdfName(item.attachmentType), writer, item.attachmentDescription);
                attachmentArray.Add(contentSpec.Reference);
            }

            // 2 add Electronic Document XMP Metadata
            ElectronicDocumentSchema ed = ElectronicDocumentSchema.generateED(attachment.attachmentName, attachment.documentVersion, attachment.documentID, attachment.documentOID);

            xmpWriter.AddRdfDescription(ed);

            string pdfaSchema = Properties.Resources.EDocument_PDFAExtensionSchema;

            // convert string to stream
            byte[] byteArray = Encoding.UTF8.GetBytes(pdfaSchema);


            //byte[] byteArray = Encoding.ASCII.GetBytes(contents);
            MemoryStream stream          = new MemoryStream(byteArray);
            IXmpMeta     edPDFAextension = XmpMetaFactory.Parse(stream);
            IXmpMeta     originalXMP     = xmpWriter.XmpMeta;

            XmpUtils.AppendProperties(edPDFAextension, originalXMP, true, true);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Evaluates a raw node value to the given value type, apply special
        /// conversions for defined types in XMP.
        /// </summary>
        /// <param name="valueType">
        ///            an int indicating the value type </param>
        /// <param name="propNode">
        ///            the node containing the value </param>
        /// <returns> Returns a literal value for the node. </returns>
        /// <exception cref="XmpException"> </exception>
        private object evaluateNodeValue(int valueType, XmpNode propNode)
        {
            object value;
            string rawValue = propNode.Value;

            switch (valueType)
            {
            case VALUE_BOOLEAN:
                value = XmpUtils.ConvertToBoolean(rawValue);
                break;

            case VALUE_INTEGER:
                value = XmpUtils.ConvertToInteger(rawValue);
                break;

            case VALUE_LONG:
                value = XmpUtils.ConvertToLong(rawValue);
                break;

            case VALUE_DOUBLE:
                value = XmpUtils.ConvertToDouble(rawValue);
                break;

            case VALUE_DATE:
                value = XmpUtils.ConvertToDate(rawValue);
                break;

            case VALUE_CALENDAR:
                IXmpDateTime dt = XmpUtils.ConvertToDate(rawValue);
                value = dt.Calendar;
                break;

            case VALUE_BASE64:
                value = XmpUtils.DecodeBase64(rawValue);
                break;

            default:
                // leaf values return empty string instead of null
                // for the other cases the converter methods provides a "null"
                // value.
                // a default value can only occur if this method is made public.
                value = rawValue != null || propNode.Options.CompositeProperty ? rawValue : "";
                break;
            }
            return(value);
        }
Exemplo n.º 11
0
 virtual public void AddRdfDescription(XmpSchema s)
 {
     try {
         String str = "<rdf:RDF xmlns:rdf=\"" + XmpConst.NS_RDF + "\">" +
                      "<rdf:Description rdf:about=\"" + xmpMeta.ObjectName +
                      "\" " +
                      s.Xmlns +
                      ">" +
                      s.ToString() +
                      "</rdf:Description></rdf:RDF>\n";
         IXmpMeta extMeta = XmpMetaFactory.ParseFromString(str);
         XmpUtils.AppendProperties(extMeta, xmpMeta, true, true);
     }
     catch (XmpException xmpExc) {
         throw new IOException(xmpExc.Message);
     }
 }
Exemplo n.º 12
0
 public void AddRdfDescription(String xmlns, String content)
 {
     try {
         String str = "<rdf:RDF xmlns:rdf=\"" + XmpConst.NS_RDF + "\">" +
                      "<rdf:Description rdf:about=\"" + xmpMeta.ObjectName +
                      "\" " +
                      xmlns +
                      ">" +
                      content +
                      "</rdf:Description></rdf:RDF>\n";
         byte[]   bytes   = Encoding.Convert(Encoding.UTF8, Encoding.ASCII, Encoding.UTF8.GetBytes(str));
         IXmpMeta extMeta = XmpMetaFactory.ParseFromString(str);
         XmpUtils.AppendProperties(extMeta, xmpMeta, true, true);
     }
     catch (XmpException xmpExc) {
         throw new IOException(xmpExc.Message);
     }
 }
Exemplo n.º 13
0
        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!");
            }
        }