ABOBE form within CTD 4.1

forum.td.development (2005-2010)
Unknown user

ABOBE form within CTD 4.1

Post by Unknown user » 16 Nov 2009, 11:44

 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();

}

}

}

Unknown user

ABOBE form within CTD 4.1

Post by Unknown user » 17 Nov 2009, 17:31

 Posted by:  Unknown 

Hi,

I've found a solution. See the following code

both objects avDoc and pdDoc have to be used

avDos is needed to get the fields within the PDF and pdDoc to save the PDF
without dialog.
If no reader is open the PDF is filled silent.

Libraries
File Include: Adobe Acrobat 7.0 Type Library.apl
File Include: AFormAut 1.0 Type Library.apl
File Include: Automation.apl

Window Variables
Number: nRet
Boolean: bOk
Number: I
String: sField
Acrobat_AcroAVDoc: avDoc
Acrobat_AcroPDDoc: pdDoc
AFORMAUTLib_AFormApp: formApp
AFORMAUTLib_IFields: formFields
AFORMAUTLib_IField: 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 )
Set bOk = formApp.PropGetFields( formFields )
Set bOk = formFields.Next( formField )
Set bOk = formField.PropGetName( sField )

! while
While sField != ""

! if
If sField = "Formular1[0].ManagerData[0].sProjectMGR[0]"
Call formField.PropSetValue( "New value
********************")
! end if

Set bOk = formFields.Next( formField )
Set bOk = formField.PropGetName( sField )
!end while

Set bOk = pdDoc.Save( 1, "C:\\Result.pdf", nRet )
Set bOk = pdDoc.Close( nRet )
Set bOk = avDoc.Close( 0, nRet )

Return to “td.development”

Who is online

Users browsing this forum: [Ccbot] and 0 guests