コード例 #1
0
        /// <summary>Merges existing XfdfObject into pdf document associated with it.</summary>
        /// <param name="xfdfObject">The object to be merged.</param>
        /// <param name="pdfDocument">The associated pdf document.</param>
        /// <param name="pdfDocumentName">The name of the associated pdf document.</param>
        internal virtual void MergeXfdfIntoPdf(XfdfObject xfdfObject, PdfDocument pdfDocument, String pdfDocumentName
                                               )
        {
            if (xfdfObject.GetF() != null && xfdfObject.GetF().GetHref() != null)
            {
                if (pdfDocumentName.EqualsIgnoreCase(xfdfObject.GetF().GetHref()))
                {
                    logger.Info("Xfdf href and pdf name are equal. Continue merge");
                }
                else
                {
                    logger.Warn(iText.IO.LogMessageConstant.XFDF_HREF_ATTRIBUTE_AND_PDF_DOCUMENT_NAME_ARE_DIFFERENT);
                }
            }
            else
            {
                logger.Warn(iText.IO.LogMessageConstant.XFDF_NO_F_OBJECT_TO_COMPARE);
            }
            //TODO check for ids original/modified compatability with those in pdf document
            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, false);

            if (form != null)
            {
                MergeFields(xfdfObject.GetFields(), form);
                MergeAnnotations(xfdfObject.GetAnnots(), pdfDocument);
            }
        }
コード例 #2
0
        public virtual void XfdfSquareAnnotationWithoutFringe()
        {
            PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new MemoryStream()));

            pdfDocument.AddNewPage();
            PdfAcroForm form        = PdfAcroForm.GetAcroForm(pdfDocument, true);
            AnnotObject annotObject = new AnnotObject();

            annotObject.SetName(XfdfConstants.SQUARE);
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.PAGE, "1"));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.RECT, "493.399638,559.179024,571.790235,600.679928"
                                                         ));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.COLOR, "#000000"));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.TITLE, "Guest"));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.FLAGS, "print"));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.DATE, "D:20200123110420-05'00'"));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.NAME, "436b0463-41e6-d3fe-b660-c3764226615b"));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.CREATION_DATE, "D:20200123110418-05'00'"));
            annotObject.AddAttribute(new AttributeObject(XfdfConstants.SUBJECT, "Rectangle"));
            AnnotsObject annotsObject = new AnnotsObject();

            annotsObject.AddAnnot(annotObject);
            XfdfObject xfdfObject = new XfdfObject();

            xfdfObject.SetAnnots(annotsObject);
            XfdfReader xfdfReader = new XfdfReader();

            xfdfReader.MergeXfdfIntoPdf(xfdfObject, pdfDocument, "smth");
            IList <PdfAnnotation> annotations = pdfDocument.GetPage(1).GetAnnotations();

            NUnit.Framework.Assert.IsNotNull(annotations);
            NUnit.Framework.Assert.AreEqual(1, annotations.Count);
            NUnit.Framework.Assert.AreEqual(PdfName.Square, annotations[0].GetSubtype());
            pdfDocument.Close();
        }
コード例 #3
0
        /// <summary>The method merges existing XfdfObject into pdf document associated with it.</summary>
        /// <param name="xfdfObject">The object ot be merged.</param>
        /// <param name="pdfDocument">The associated pdf document.</param>
        /// <param name="pdfDocumentName">The name of the associated pdf document.</param>
        internal virtual void MergeXfdfIntoPdf(XfdfObject xfdfObject, PdfDocument pdfDocument, String pdfDocumentName
                                               )
        {
            if (xfdfObject.GetF() != null && xfdfObject.GetF().GetHref() != null)
            {
                if (pdfDocumentName.EqualsIgnoreCase(xfdfObject.GetF().GetHref()))
                {
                    logger.Info("Xfdf href and pdf name are equal. Continue merge");
                }
                else
                {
                    logger.Warn("Xfdf href attribute and pdfDocument name are different!");
                }
            }
            else
            {
                logger.Warn("No f object to compare.");
            }
            //TODO check for ids original/modified compatability with those in pdf document
            PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDocument, false);

            if (form != null)
            {
                MergeFields(xfdfObject.GetFields(), form);
                MergeAnnotations(xfdfObject.GetAnnots(), pdfDocument);
            }
        }
コード例 #4
0
ファイル: XfdfWriter.cs プロジェクト: outrera/itext7-dotnet
        private void WriteDom(XfdfObject xfdfObject)
        {
            XmlDocument document = XfdfFileUtils.CreateNewXfdfDocument();
            // root xfdf element
            XmlElement root = document.CreateElement("xfdf");

            document.AppendChild(root);
            //write fields
            if (xfdfObject.GetFields() != null && xfdfObject.GetFields().GetFieldList() != null && !xfdfObject.GetFields
                    ().GetFieldList().IsEmpty())
            {
                XmlElement fields = document.CreateElement("fields");
                root.AppendChild(fields);
                IList <FieldObject> fieldList = xfdfObject.GetFields().GetFieldList();
                foreach (FieldObject fieldObject in fieldList)
                {
                    if (fieldObject.GetParent() == null)
                    {
                        AddField(fieldObject, fields, document, fieldList);
                    }
                }
            }
            //write annots
            if (xfdfObject.GetAnnots() != null && xfdfObject.GetAnnots().GetAnnotsList() != null && !xfdfObject.GetAnnots
                    ().GetAnnotsList().IsEmpty())
            {
                XmlElement annots = document.CreateElement("annots");
                root.AppendChild(annots);
                foreach (AnnotObject annotObject in xfdfObject.GetAnnots().GetAnnotsList())
                {
                    AddAnnot(annotObject, annots, document);
                }
            }
            //write f
            if (xfdfObject.GetF() != null)
            {
                XmlElement f = document.CreateElement("f");
                AddFAttributes(xfdfObject.GetF(), f);
                root.AppendChild(f);
            }
            //write ids
            if (xfdfObject.GetIds() != null)
            {
                XmlElement ids = document.CreateElement("ids");
                AddIdsAttributes(xfdfObject.GetIds(), ids);
                root.AppendChild(ids);
            }
            // create the xml file
            //transform the DOM Object to an XML File
            XfdfFileUtils.SaveXfdfDocumentToFile(document, this.outputStream);
        }
コード例 #5
0
ファイル: XfdfWriter.cs プロジェクト: outrera/itext7-dotnet
 /// <summary>
 /// Writes data from
 /// <see cref="XfdfObject"/>
 /// into a xfdf data file.
 /// </summary>
 /// <param name="xfdfObject">
 ///
 /// <see cref="XfdfObject"/>
 /// containing the data.
 /// </param>
 internal virtual void Write(XfdfObject xfdfObject)
 {
     this.WriteDom(xfdfObject);
 }