Skip to main content
Participant
July 29, 2022
Question

IAC : C# : Is it possible to get bounding box of a field as an AcroRect object ?

  • July 29, 2022
  • 2 replies
  • 594 views

Is it possible to get bounding box of a field as an AcroRect object ?

 

CAcroApp acroApp = new AcroAppClass();  
CAcroAVDoc avDoc = new AcroAVDocClass();
CAcroRect acroRect = new AcroRectClass();
CAcroPDDoc pDDoc = new AcroPDDocClass();

if (!avDoc.Open(sample_pdf, ""))
  return;
else
  pDDoc = (CAcroPDDoc)avDoc.GetPDDoc();

IAFormApp formApp = new AFormAppClass();
IFields myFields = (IFields)formApp.Fields;
IEnumerator myEnumerator = myFields.GetEnumerator();

while (myEnumerator.MoveNext())
{
  IField myField = (IField)myEnumerator.Current;
  string fieldName = myField.Name;
  string fieldType = myField.Type;
}

 

I need to replace  myField of  type checkbox to a text field of same size at same location. I can remove checkbox by 

 

while (myEnumerator.MoveNext())
{
  IField myField = (IField)myEnumerator.Current;
  string fieldName = myField.Name;
  string fieldType = myField.Type;
  //Remove Checkbox field type
  if(fieldType=="checkbox")
     myFields.Remove(fieldName);
}

 

How can I add a text type field in the same position of checkbox ?

 

 
if(fieldType=="checkbox")
{
//Remove Checkbox field type
  myFields.Remove(fieldName);
//Add text field type
  myFields.Add(fieldName, "text", 0, acroRect.Left, acroRect.Top, acroRect.right, acroRect.bottom); // how to get acroRect object of a field ??
}
     

 

This topic has been closed for replies.

2 replies

Legend
August 2, 2022

The APIs you are using were frozen some 20 years ago, and you need to be looking at the JavaScript methods. The Field object in JavaScript does have a "rect" property. Caution: a field may appear in multiple positions with the same name, and you need to code to at least take that into account. The discussion of the Field object shows how to distinguish. 

Bernd Alheit
Community Expert
Community Expert
July 29, 2022

Try the forum for Acrobat SDK.

Participant
August 1, 2022

Isn't this the acrobat SDK forum?

Bernd Alheit
Community Expert
Community Expert
August 1, 2022

Someone has moved it.