コード例 #1
0
 internal static void AppendMetadataToInfo(byte[] xmpMetadata, PdfDocumentInfo info)
 {
     if (xmpMetadata != null)
     {
         try {
             XMPMeta     meta  = XMPMetaFactory.ParseFromBuffer(xmpMetadata);
             XMPProperty title = meta.GetLocalizedText(XMPConst.NS_DC, PdfConst.Title, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT
                                                       );
             if (title != null)
             {
                 info.SetTitle(title.GetValue());
             }
             String author = FetchArrayIntoString(meta, XMPConst.NS_DC, PdfConst.Creator);
             if (author != null)
             {
                 info.SetAuthor(author);
             }
             // We assume that pdf:keywords has precedence over dc:subject
             XMPProperty keywords = meta.GetProperty(XMPConst.NS_PDF, PdfConst.Keywords);
             if (keywords != null)
             {
                 info.SetKeywords(keywords.GetValue());
             }
             else
             {
                 String keywordsStr = FetchArrayIntoString(meta, XMPConst.NS_DC, PdfConst.Subject);
                 if (keywordsStr != null)
                 {
                     info.SetKeywords(keywordsStr);
                 }
             }
             XMPProperty subject = meta.GetLocalizedText(XMPConst.NS_DC, PdfConst.Description, XMPConst.X_DEFAULT, XMPConst
                                                         .X_DEFAULT);
             if (subject != null)
             {
                 info.SetSubject(subject.GetValue());
             }
             XMPProperty creator = meta.GetProperty(XMPConst.NS_XMP, PdfConst.CreatorTool);
             if (creator != null)
             {
                 info.SetCreator(creator.GetValue());
             }
             XMPProperty producer = meta.GetProperty(XMPConst.NS_PDF, PdfConst.Producer);
             if (producer != null)
             {
                 info.Put(PdfName.Producer, new PdfString(producer.GetValue(), PdfEncodings.UNICODE_BIG));
             }
             XMPProperty trapped = meta.GetProperty(XMPConst.NS_PDF, PdfConst.Trapped);
             if (trapped != null)
             {
                 info.SetTrapped(new PdfName(trapped.GetValue()));
             }
         }
         catch (XMPException) {
         }
     }
 }
コード例 #2
0
 public virtual void MetadataReadingInEncryptedDoc()
 {
     PdfReader reader = new PdfReader(sourceFolder + "encryptedWithPlainMetadata.pdf", new ReaderProperties().SetPassword
         (OWNER));
     PdfDocument doc = new PdfDocument(reader);
     XMPMeta xmpMeta = XMPMetaFactory.ParseFromBuffer(doc.GetXmpMetadata());
     XMPProperty creatorToolXmp = xmpMeta.GetProperty(XMPConst.NS_XMP, "CreatorTool");
     doc.Close();
     NUnit.Framework.Assert.IsNotNull(creatorToolXmp);
     NUnit.Framework.Assert.AreEqual("iText 7", creatorToolXmp.GetValue());
 }
コード例 #3
0
        /// <exception cref="iText.Kernel.XMP.XMPException"/>
        private static void AppendArrayItemIfDoesNotExist(XMPMeta meta, String ns, String arrayName, String value)
        {
            int currentCnt = meta.CountArrayItems(ns, arrayName);

            for (int i = 0; i < currentCnt; i++)
            {
                XMPProperty item = meta.GetArrayItem(ns, arrayName, i + 1);
                if (value.Equals(item.GetValue()))
                {
                    return;
                }
            }
            meta.AppendArrayItem(ns, arrayName, new PropertyOptions(PropertyOptions.ARRAY_ORDERED), value, null);
        }
コード例 #4
0
        public static iText.Kernel.Pdf.PdfAConformanceLevel GetConformanceLevel(XMPMeta meta)
        {
            XMPProperty conformanceXmpProperty = null;
            XMPProperty partXmpProperty        = null;

            try {
                conformanceXmpProperty = meta.GetProperty(XMPConst.NS_PDFA_ID, XMPConst.CONFORMANCE);
                partXmpProperty        = meta.GetProperty(XMPConst.NS_PDFA_ID, XMPConst.PART);
            }
            catch (XMPException) {
            }
            if (conformanceXmpProperty == null || partXmpProperty == null)
            {
                return(null);
            }
            else
            {
                String conformance = conformanceXmpProperty.GetValue();
                String part        = partXmpProperty.GetValue();
                return(GetConformanceLevel(part, conformance));
            }
        }
コード例 #5
0
        /// <exception cref="iText.Kernel.XMP.XMPException"/>
        private static String FetchArrayIntoString(XMPMeta meta, String ns, String arrayName)
        {
            int           keywordsCnt = meta.CountArrayItems(ns, arrayName);
            StringBuilder sb          = null;

            for (int i = 0; i < keywordsCnt; i++)
            {
                XMPProperty curKeyword = meta.GetArrayItem(ns, arrayName, i + 1);
                if (sb == null)
                {
                    sb = new StringBuilder();
                }
                else
                {
                    if (sb.Length > 0)
                    {
                        sb.Append("; ");
                    }
                }
                sb.Append(curKeyword.GetValue());
            }
            return(sb != null?sb.ToString() : null);
        }