Esempio n. 1
0
        public virtual void XfaExternalConnectionTest()
        {
            String inFileName  = sourceFolder + "xfaExternalConnection.pdf";
            String outFileName = destinationFolder + "outXfaExternalConnection.pdf";
            String cmpFileName = sourceFolder + "cmp_outXfaExternalConnection.pdf";

#if NETSTANDARD2_0
            using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inFileName), new PdfWriter(outFileName).SetCompressionLevel
                                                            (CompressionConstants.NO_COMPRESSION))) {
                NUnit.Framework.Assert.That(() =>
                {
                    // the line below is expected to produce an exception
                    PdfAcroForm.GetAcroForm(pdfDoc, true);
                }
                                            , NUnit.Framework.Throws.InstanceOf <XmlException>().With.Message.EqualTo("Reference to undeclared entity 'xxe'. Line 124, position 64."));
            }
#endif

#if !NETSTANDARD2_0
            using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inFileName), new PdfWriter(outFileName).SetCompressionLevel
                                                            (CompressionConstants.NO_COMPRESSION))) {
                PdfAcroForm form = PdfAcroForm.GetAcroForm(pdfDoc, true);
                // server fills out a field
                form.GetField("TestField").SetValue("testvalue");
                form.GetXfaForm().Write(pdfDoc);
            }
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             ));
#endif
        }
Esempio n. 2
0
        protected void ManipulatePdf(string dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(SRC));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfDoc, true);
            XfaForm     xfa    = form.GetXfaForm();

            // Get XFA data under datasets/data.
            XElement            node = xfa.GetDatasetsNode();
            IEnumerable <XNode> list = node.Nodes();

            foreach (XNode item in list)
            {
                if (item is XElement && "data".Equals(((XElement)item).Name.LocalName))
                {
                    node = (XElement)item;
                    break;
                }
            }

            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Indent = true;
            XmlWriter writer = XmlWriter.Create(dest, settings);

            node.WriteTo(writer);
            writer.Close();

            pdfDoc.Close();
        }
Esempio n. 3
0
        public virtual void FindFieldNameWithoutDataSet()
        {
            String      inFileName  = sourceFolder + "TextField1_empty.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName));
            PdfAcroForm acroForm    = PdfAcroForm.GetAcroForm(pdfDocument, true);
            XfaForm     xfaForm     = acroForm.GetXfaForm();
            String      name        = xfaForm.FindFieldName("TextField1");

            NUnit.Framework.Assert.IsNull(name);
        }
Esempio n. 4
0
        public virtual void FindFieldName()
        {
            String      inFileName  = sourceFolder + "TextField1.pdf";
            PdfDocument pdfDocument = new PdfDocument(new PdfReader(inFileName));
            PdfAcroForm acroForm    = PdfAcroForm.GetAcroForm(pdfDocument, true);
            XfaForm     xfaForm     = acroForm.GetXfaForm();

            xfaForm.FindFieldName("TextField1");
            String secondRun = xfaForm.FindFieldName("TextField1");

            NUnit.Framework.Assert.IsNotNull(secondRun);
        }
Esempio n. 5
0
        protected void ManipulatePdf(string dest)
        {
            PdfDocument pdfdoc = new PdfDocument(new PdfReader(SRC), new PdfWriter(dest));
            PdfAcroForm form   = PdfAcroForm.GetAcroForm(pdfdoc, true);

            XfaForm xfa = form.GetXfaForm();

            // Method fills this object with XFA data under datasets/data.
            xfa.FillXfaForm(new FileStream(XML, FileMode.Open, FileAccess.Read));
            xfa.Write(pdfdoc);

            pdfdoc.Close();
        }