Ejemplo n.º 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();
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 3
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();
        }