Planet PDF Forum Archive

Planet PDF ForumWowsers! This is page is old, head to the LIVE Planet PDF Forum. It features more than 10 conferences, covering everything from beginner to in-depth developer and pre-press discussions. If you wish to continue... one & two archive covers 1999-2011 (160,000 pages).

New Forum | Previous | Next | (P-PDF) Beginners

Topic: need help with automated form filling
Conf: (P-PDF) Beginners, Msg: 131435
From: masbury
Date: 4/21/2005 12:12 AM

I have a pdf "template" and an xml file (using Acrobat 7). I need to be able to silently (i.e. not show the viewer) combine the data into the template and save it as a new "filled-out" form. I was looking through the examples that came with the SDK, and I'm using the following C# (modified by me) to do something similar to what I want. But it's using an "avDoc" object and won't save the result to a new PDF. What I "think" I need to do is use a "PDDoc" object, but I can't find any good examples of this. Here is the code that I'm using for now. Any suggestions?



Copyright (C) 1994-2004 Adobe Systems Incorporated
All rights reserved.

NOTICE: Adobe permits you to use, modify, and distribute this file
in accordance with the terms of the Adobe license agreement
accompanying it. If you have received this file from a source other
than Adobe, then your use, modification, or distribution of it
requires the prior written permission of Adobe.

- This is a simple Acrobat IAC C# sample(C# Console project). It
includes code to launch Acrobat Viewer, open a PDF file
(C:\SampleForm.pdf), fill the form field "Name" with value
"John Doe". The sample leaves the document "SampleForm.pdf" open
after the application exits on purpose. To keep the pdf document
open after the application exits, you should utilize the CAcroAVDoc
class rather than the CAcroPDDoc class.
- The way to set up using Acrobat IAC in the project is from the menu
Project -> Add References... -> COM to select Acrobat.
- The way to set up using Form IAC in the project is from the menu
Project -> Add References... -> COM to select "AFormAut 1.0 Type
- To run the sample, copy the file "SampleForm.pdf" from the "FillFormCS"
folder to C:\.
using System;
using System.Collections;
using Acrobat;
using AFORMAUTLib;
using System.Xml;

namespace FillFormCS

/// Summary description for FillFormCS.

class FillFormCS
// Hard-coded file name, it can be changed when needed.
const string FORM_NAME = "C:\\my_form.pdf";
/// The main entry point for the application.

static void Main(string[] args)
// Initialize Acrobat by creting App object.
CAcroApp acroApp = new AcroAppClass();

// Create an AVDoc object
CAcroAVDoc avDoc = new AcroAVDocClass();

// Open the pdf
if(!avDoc.Open (FORM_NAME, ""))
string szMsg = "Cannot open" + FORM_NAME + ".\n"
+ "The program is over.";

// Create a IAFormApp object, so that we can access the form fields in
// the open document
IAFormApp formApp = new AFormAppClass();

// Get the IFields object associated with the form
IFields myFields = (IFields)formApp.Fields;

// Get the IEnumerator object for myFields
IEnumerator myEnumerator = myFields.GetEnumerator();

bool bFound = false;

System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader("c:\\my_form.xml");
string TagName = "";
string TagValue = "";
while (reader.Read())
if (reader.NodeType == System.Xml.XmlNodeType.Element)
TagName = reader.Name;
if (reader.NodeType == System.Xml.XmlNodeType.Text)
TagValue = reader.Value;
if(TagValue != null){
// Get the IField object
IField myField = (IField)myEnumerator.Current;
if(myField.Name.IndexOf(TagName,0,myField.Name.Length) > 0)
bFound = true;
myField.Value = TagValue;
Console.WriteLine(myField.Name + " : " + myField.Value);
myEnumerator = myFields.GetEnumerator();


PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link...

Download free demo

Debenu PDF Tools Pro

It's simple to use and will let you preview and edit PDF files, it's a Windows application that makes...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.