コード例 #1
0
        public virtual void NullProducerTest()
        {
            String inputFile = SOURCE_FOLDER + "nullProducer.pdf";

            using (PdfDocument document = new PdfDocument(new PdfReader(inputFile))) {
                PdfDocumentInfo documentInfo = document.GetDocumentInfo();
                NUnit.Framework.Assert.AreEqual(PdfNull.PDF_NULL, documentInfo.GetPdfObject().Get(PdfName.Producer));
                NUnit.Framework.Assert.IsNull(documentInfo.GetProducer());
            }
            using (PdfDocument document_1 = new PdfDocument(new PdfReader(inputFile), new PdfWriter(new MemoryStream()
                                                                                                    ))) {
                PdfDocumentInfo documentInfo = document_1.GetDocumentInfo();
                NUnit.Framework.Assert.IsNotNull(documentInfo.GetPdfObject().Get(PdfName.Producer));
                NUnit.Framework.Assert.IsNotNull(document_1.GetDocumentInfo().GetProducer());
            }
        }
コード例 #2
0
        /// <exception cref="iText.Kernel.XMP.XMPException"/>
        internal static void AppendDocumentInfoToMetadata(PdfDocumentInfo info, XMPMeta xmpMeta)
        {
            PdfDictionary docInfo = info.GetPdfObject();

            if (docInfo != null)
            {
                PdfName   key;
                PdfObject obj;
                String    value;
                foreach (PdfName pdfName in docInfo.KeySet())
                {
                    key = pdfName;
                    obj = docInfo.Get(key);
                    if (obj == null)
                    {
                        continue;
                    }
                    if (obj.IsString())
                    {
                        value = ((PdfString)obj).ToUnicodeString();
                    }
                    else
                    {
                        if (obj.IsName())
                        {
                            value = ((PdfName)obj).GetValue();
                        }
                        else
                        {
                            continue;
                        }
                    }
                    if (PdfName.Title.Equals(key))
                    {
                        xmpMeta.SetLocalizedText(XMPConst.NS_DC, PdfConst.Title, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, value);
                    }
                    else
                    {
                        if (PdfName.Author.Equals(key))
                        {
                            foreach (String v in iText.IO.Util.StringUtil.Split(value, ",|;"))
                            {
                                if (v.Trim().Length > 0)
                                {
                                    AppendArrayItemIfDoesNotExist(xmpMeta, XMPConst.NS_DC, PdfConst.Creator, v.Trim(), PropertyOptions.ARRAY_ORDERED
                                                                  );
                                }
                            }
                        }
                        else
                        {
                            if (PdfName.Subject.Equals(key))
                            {
                                xmpMeta.SetLocalizedText(XMPConst.NS_DC, PdfConst.Description, XMPConst.X_DEFAULT, XMPConst.X_DEFAULT, value
                                                         );
                            }
                            else
                            {
                                if (PdfName.Keywords.Equals(key))
                                {
                                    foreach (String v in iText.IO.Util.StringUtil.Split(value, ",|;"))
                                    {
                                        if (v.Trim().Length > 0)
                                        {
                                            AppendArrayItemIfDoesNotExist(xmpMeta, XMPConst.NS_DC, PdfConst.Subject, v.Trim(), PropertyOptions.ARRAY);
                                        }
                                    }
                                    xmpMeta.SetProperty(XMPConst.NS_PDF, PdfConst.Keywords, value);
                                }
                                else
                                {
                                    if (PdfName.Creator.Equals(key))
                                    {
                                        xmpMeta.SetProperty(XMPConst.NS_XMP, PdfConst.CreatorTool, value);
                                    }
                                    else
                                    {
                                        if (PdfName.Producer.Equals(key))
                                        {
                                            xmpMeta.SetProperty(XMPConst.NS_PDF, PdfConst.Producer, value);
                                        }
                                        else
                                        {
                                            if (PdfName.CreationDate.Equals(key))
                                            {
                                                xmpMeta.SetProperty(XMPConst.NS_XMP, PdfConst.CreateDate, PdfDate.GetW3CDate(value));
                                            }
                                            else
                                            {
                                                if (PdfName.ModDate.Equals(key))
                                                {
                                                    xmpMeta.SetProperty(XMPConst.NS_XMP, PdfConst.ModifyDate, PdfDate.GetW3CDate(value));
                                                }
                                                else
                                                {
                                                    if (PdfName.Trapped.Equals(key))
                                                    {
                                                        xmpMeta.SetProperty(XMPConst.NS_PDF, PdfConst.Trapped, value);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }