
Adobe Acrobat SDK
Working with Documents and Files
Developing Plug-ins and Applications
Creating a PDDoc object based on an open PDF document 84
The following code example creates a
PDDoc
object that is based on a PDF file named PurchaseOrder.pdf
and located in the root of the C drive. This code example is located within a user-defined function named
getDocument
.
Example 5.3
Creating a PDDoc object
PDDoc getDocument()
{
//Declare a PDDoc object
PDDoc myPDDoc;
//Declare a PDAuthProc callback
PDAuthProc myAuthProcPtr;
//Specify the PDF file on which to base the PDDoc object
const char * myPath = "C:\\PurchaseOrder.pdf";
ASAtom pathType = ASAtomFromString("Cstring");
//Create an ASPathName object
ASFileSys fileSys = ASGetDefaultFileSysForPath(pathType, myPath);
ASPathName pathName = ASFileSysCreatePathName(fileSys,pathType,
myPath,NULL);
//Create the authentication callback
myAuthProcPtr = ASCallbackCreateProto (PDAuthProc,&authProc);
//Create a PDDoc object
myPDDoc = PDDocOpen (pathName, fileSys, myAuthProcPtr, false);
//Release the callback
ASCallbackDestroy (myAuthProcPtr);
return myPDDoc;
}
ASBool authProc(PDDoc TheDoc)
{
//Define business logic that authenticates the user
return true;
}
Creating a PDDoc object based on an open PDF document
You can create a
PDDoc
object that is based on a PDF document that is currently open by performing the
following tasks:
1. Create an
AVDoc
object by invoking the
AVAppGetActiveDoc
method. This method gets the
frontmost document located within Adobe Reader or Acrobat.
2. Create a
PDDoc
object by invoking the
AVDocGetPDDoc
method. This method requires an
AVDoc
object and returns a
PDDoc
object.