Article View: adobe.acrobat.reader
Article #526Re: Automation Questions
From: andreibardin
Date: Thu, 10 Nov 2005 12:33
Date: Thu, 10 Nov 2005 12:33
104 lines
4486 bytes
4486 bytes
The following is the standard sample code from Acrobat SDK in C#:
/*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>
/// Summary description for FillFormCS.
/// </summary>
class FillFormCS
{
// Hard-coded file name, it can be changed when needed.
const string FORM_NAME = "d:\\SampleForm.pdf";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// Initialize Acrobat by cretaing App object.
CAcroApp acroApp = new AcroAppClass();
// Show Acrobat Viewer
acroApp.Show();
// 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.";
Console.WriteLine(szMsg);
return;
}
// 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 "Name", set it's value to "John Doe"
if(myField.Name == "Name")
{
bFound = true;
myField.Value = "John Doe";
break;
}
}
if(bFound)
Console.WriteLine("Sucessfully changed the \"Name\" field value to
\"John Doe\".");
else
Console.WriteLine("Failed to locate the \"Name\" field in the
form.");
}
}
}
Technical Details
Message-ID:
<1131626032.924079.223340@z14g2000cwz.googlegroups.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mailReferences:
<o4CdnVM7uaVqYOzeRVn-ug@comcast.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 109513,b8f2b5261e4d61d7 X-Google-Thread: 10177e,b8f2b5261e4d61d7 X-Google-Attributes: gid109513,gid10177e,public X-Google-Language: ENGLISH,ASCII-7-bit Path: arc1-ca.pugleaf.net!g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: andreibardin@hotmail.com Newsgroups: adobe.acrobat.reader,adobe.acrobat.sdk Subject: Re: Automation Questions Date: 10 Nov 2005 04:33:52 -0800 Organization: http://groups.google.com Lines: 105 Message-ID: <1131626032.924079.223340@z14g2000cwz.googlegroups.com> References: <o4CdnVM7uaVqYOzeRVn-ug@comcast.com> NNTP-Posting-Host: 216.239.87.122 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1131626037 20549 127.0.0.1 (10 Nov 2005 12:33:57 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 10 Nov 2005 12:33:57 +0000 (UTC) In-Reply-To: <o4CdnVM7uaVqYOzeRVn-ug@comcast.com> User-Agent: G2/0.2 X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50215),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=216.239.87.122; posting-account=hD6pXg0AAAA8i6qOZEAG80JVN4i6eZlm