Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 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);
            }
        }