
Adobe Acrobat SDK
Working with Acrobat Extended APIs
Developing Plug-ins and Applications
Registering agents with consultants 225
Registering agents with consultants
In order to modify or analyze documents, you must register your agent with the consultant by invoking
the
ConsultantRegisterAgent
method.
Once the agent is registered with the consultant, it remains registered until a call to
ConsultantTraverseFrom
is made. You must re-register agents before each successive call to
ConsultantTraverseFrom
.
When you register an agent, you supply a rule (one of the
RegAgentFlag
values) for revisitation of
objects as the consultant runs through the document from the starting object. The following code
example registers an agent with a consultant.
Example 20.2
Registering an agent with a consultant
//Declare volatile consultant because it is inside a DURING bloc
Consultant volatile hConsultant = (Consultant)NULL;
DURING
AVDoc hAVDoc = AVAppGetActiveDoc();
miAssert(hAVDoc != ( AVDoc )NULL );
if( hAVDoc != ( AVDoc )NULL )
{
//Create a Consultant object
hConsultant = ConsultantCreate(
DumpAllObjectsAgentPercentDone );
miAssert( hConsultant != ( Consultant )NULL );
if( hConsultant != ( Consultant )NULL )
{
//Get the current document root
PDDoc hPDDoc = AVDocGetPDDoc(hAVDoc);
//Create an agent and register it
gDumpAllObjectsAgent = new DumpAllObjectsAgent(hPDDoc);
if((gDumpAllObjectsAgent == (DumpAllObjectsAgent*)NULL)
|| (gDumpAllObjectsAgent->IsValid() == false))
{
ASRaise(GenError(genErrNoMemory) );
}
else
{
ConsultantRegisterAgent(hConsultant,*gDumpAllObjectsAgent,
REG_REVISITRECLASS_ALL );
//Start the consultant
ConsultantTraverseFrom(hConsultant,
CosDocGetRoot(PDDocGetCosDoc(hPDDoc)),PT_CATALOG);
}
}
}
HANDLER
... Destroy Consultant...Free Memory...
END_HANDLER