Accessing and modifying PDF form elements (data) using C#

The PDF Creator enables you to create secure PDF documents and to view, print and process existing PDF documents.
If you have any questions about the installation and usage of the PDF Creator please post them here.
Post Reply
Posts: 1
Joined: Tue Sep 04 2007

Accessing and modifying PDF form elements (data) using C#

Post by josborne » Wed Sep 05 2007

I am trying to use your products to do the following in a C# application I am developing:

1) Open an existing pdf document that contains PDF forms controls.
2) Set the forms controls content to contain data from another application.
3) Allow a user to then edit this data using the viewer GUI control.
4) Save the modified values the user has changed back to the other application.

I was attempting to use your PDF Creator .NET, and the performance of the component drawing itself on the screen after loading a complicated form or after being minimized/maximized is too slow in some cases. It can take nearly a minute to redraw in some cases, and this is just too slow for my needs.

Therefore, I would need to use the PDF Creator for ActiveX component instead, as it seems to perform at least an order of magnitude faster (loads documents in a few seconds instead of a minute), and will work better for my needs.

Using the PDF Creator .NET I was able to access the PDF form fields using code similar to the following:

IacDocument doc;
IacObject iacObj;

for (int i = 0; i < doc.PageCount; i++)
IacAttribute attribute = doc.GetPage(i).AttributeByName("Objects");
ArrayList listobj = (ArrayList)attribute.Value;

foreach (object o in listobj)
iacObj = (IacObject)o;

//Check to ensure value is a PDF Forms text component (ObjectType = 6)
if (iacObj.AttributeByName("ObjectType").Value.ToString() == "6")
string x = (string)iacObj.AttributeByName("Text").Value;

Now I need code that performs something similar using the interface to the ActiveX control. I was able to add the control correctly to a Windows Formin my C# application, and can load the document, but I am having trouble trying to access the values for the forms components on each page. I have looked at the documentation available for the ActiveX control but am still stuck.

The following code retrieves each page in the document, however attempting to get the "Objects" attribute for each page always returns an empty object array, instead of an array with all of the objects in the page as the code above for the .NET component would:

this.axPDFCreactiveX1.Open(openFileDialog1.FileName, string.Empty);

IacAttribute attribute;
object[] objects;

//Grab an array of all the pages in the document...
object[] pages = (object[])this.axPDFCreactiveX1.get_ObjectAttribute("Document", "Pages");

for (int i = 0; i < pages.Length; i++)
//For each page grab the "Objects" attribute for that page
IacObject page = (ACPDFCREACTIVEX.IacObject)pages;
attribute = (IacAttribute)page.get_Evaluate("Objects");

//The object[] below is always empty....?
objects = (object[])attribute.Value;

Since this method obviously does not work, what would I need to do to get all of the objects for each page in a document to be able to get and set their values?

Additionally, would I need to do anything to synchronize the document again after the user has modified it to ensure that the values I read from the document control contain the new values the user has modified and not the values that were initially set?

Thanks for any assistance, as I haven't found much documentation regarding interfacing to the ActiveX component to do anything with PDF forms data, especially from C#.

Post Reply