Example #1
0
        public void ManipulatePdf()
        {
            // Create a pdf document instance
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(INPUT_PDF), new PdfWriter(DEST));

            // Load the DOM Document
            XfaForm   xfa    = PdfAcroForm.GetAcroForm(pdfDoc, false).GetXfaForm();
            XDocument domDoc = xfa.GetDomDocument();

            // This works for the specific document
            // Generate the list of calculate amount Nodes
            IEnumerable <XElement> calcElements = findCalc(domDoc);

            // Update calculate value
            foreach (XElement element in calcElements)
            {
                XElement calc   = element.Descendants().First();
                String   curVal = calc.Value;
                calc.Value = "2*" + curVal;
                Console.WriteLine(calc.Value);
            }

            // Write XFA back to PDF Document
            xfa.SetDomDocument(domDoc);
            xfa.Write(pdfDoc);
            pdfDoc.Close();
        }
Example #2
0
        public void ManipulatePdf()
        {
            // Create a PDF document instance
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(INPUT_PDF), new PdfWriter(DEST));

            // Load the DOM Document
            XfaForm   xfa    = PdfAcroForm.GetAcroForm(pdfDoc, false).GetXfaForm();
            XDocument domDoc = xfa.GetDomDocument();

            // The follwing 2 lines of code only work for the specific document
            // Access the Script Node of the DOM Document
            XElement template = domDoc.Descendants().First().Descendants().First().ElementsAfterSelf().First();
            XElement script   = template.Descendants().First().Descendants().First().ElementsAfterSelf().First()
                                .Descendants().First().ElementsAfterSelf().First().ElementsAfterSelf().First().ElementsAfterSelf()
                                .First().ElementsAfterSelf().First().ElementsAfterSelf().First().Descendants().First();

            // Update the script message
            String message = "xfa.host.messageBox(\"XFA SCRIPT Message!!!\")";

            script.SetValue(message);

            // Write XFA back to PDF Document
            xfa.SetDomDocument(domDoc);
            xfa.Write(pdfDoc);
            pdfDoc.Close();
        }
Example #3
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();
        }
Example #4
0
        public void ManipulatePdf()
        {
            // Create a pdf document instance
            PdfDocument pdfDoc = new PdfDocument(new PdfReader(INPUT_PDF), new PdfWriter(DEST));

            // Load the DOM Document
            XfaForm   xfa    = PdfAcroForm.GetAcroForm(pdfDoc, false).GetXfaForm();
            XDocument domDoc = xfa.GetDomDocument();

            // The follwing 2 lines of code only work for the specific document
            // Access the Script Node of the DOM Document
            XElement template = domDoc.Descendants().First().Descendants().First().ElementsAfterSelf().First();
            XElement script   = template.Descendants().First().Descendants().First().ElementsAfterSelf().First()
                                .Descendants().First().ElementsAfterSelf().First().ElementsAfterSelf().First().ElementsAfterSelf()
                                .First().ElementsAfterSelf().First().ElementsAfterSelf().First().Descendants().First();

            // Remove the Script from the Node
            script.SetValue("");

            // Write XFA back to the PDF Document
            xfa.SetDomDocument(domDoc);
            xfa.Write(pdfDoc);
            pdfDoc.Close();
        }