Posted by: Unknown
Hallo NG,
Within my Application I have to fill (and read) an ADOBE form with values
from an database.
The way I would do this is:
Open a template, fill the fields with the values and save the PDF under a
different name.
Opening and saving works fine, but I don't know how to initialise the fields
in the ADOBE form and then work through the form with a loop to read the
value from each field.
Perhaps has someone a hint!
with best reagards
Volker
I use CTD 4.1 PTF2
Here my CTD definition of the variables and the code to open and save the
PDF.
Libraries
File Include: Adobe Acrobat 7.0 Type Library.apl
File Include: AFormAut 1.0 Type Library.apl
File Include: Automation.apl
Windows Variables
Number: nRet
Boolean: bOk
!Acrobat_AcroAVDoc: avDoc
Acrobat_AcroPDDoc: pdDoc
AFORMAUTLib_AFormApp: formApp
AFORMAUTLib_Fields: formFields
AFORMAUTLib_Field: formField
On SAM_Create
Set bOk = avDoc.Create( )
Set bOk = pdDoc.Create( )
Set bOk = formApp.Create( )
Set bOk = avDoc.Open( "C:\\Template.pdf", "", nRet )
Set bOk = pdDoc.Open( "C:\\Template.pdf", nRet )
!
! what to do here ??????
!
Set bOk = pdDoc.Save( 1, "C:\\Result.pdf", nRet )
Set bOk = pdDoc.Close( nRet )
Set bOk = avDoc.Close( 0, nRet )
The following sample in C# from ABOBE runs fine !!!!!!!
/*ADOBE SYSTEMS INCORPORATED
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.
------------------------------------------------------------
FillFormCS
- 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
Library".
- To run the sample, copy the file "SampleForm.pdf" from the "FillFormCS"
folder to C:\.
------------------------------------------------------------*/
using System;
using System.Collections;
using Acrobat;
using AFORMAUTLib;
namespace FillFormCS
{
///
/// Summary description for FillFormCS.
///
class FillFormCS
{
// Hard-coded file name, it can be changed
when needed.
const string FORM_NAME = "C:\\Template.pdf";
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
// Create an AVDoc object
CAcroAVDoc avDoc = new
AcroAVDocClass();
CAcroPDDoc pdDoc = new
AcroPDDocClass();
// Open the pdf
if(!avDoc.Open
(FORM_NAME,""))
{
string szMsg
= "Cannot open" + FORM_NAME + ".\n"
+ "The program is over.";
Console.WriteLine(szMsg);
return;
}
pdDoc.Open (FORM_NAME);
// how is the following to do
in CDT?????
// 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;
// Fill the "Name" field with
value "John Doe"
while(myEnumerator.MoveNext())
{
// Get the
IField object
IField
myField = (IField)myEnumerator.Current;
// If the
field is "Formular1[0].TF1[0].Fachlicher_Leiter[0]",
// set it's
value to "This is the new Value!!"
if(myField.Name
== "Formular1[0].TF1[0].Fachlicher_Leiter[0]")
{
bFound = true;
myField.Value = "This is the new Value!!";
break;
}
}
//-----------------------------------------------------
pdDoc.Save(1,
"C:\\Result.pdf");
pdDoc.Close();
}
}
}