
Adobe Acrobat SDK
Working with Cos Objects
Developing Plug-ins and Applications
Creating Cos streams 192
Example 17.10
Creating a stream dictionary
//Create a PDPage object using the current page
AVDoc avDoc = AVAppGetActiveDoc();
AVPageView pageView = AVDocGetPageView(avDoc);
PDPageNumber pageNum = AVPageViewGetPageNum(pageView);
PDDoc pdDoc = AVDocGetPDDoc(avDoc);
PDPage pdPage = PDDocAcquirePage(pdDoc, pageNum);
//Use the PDPage object to get the CosDoc object
CosDoc cd = PDDocGetCosDoc(PDPageGetDoc(pdPage));
//Define a stream to draw a line
char buf [500];
sprintf(buf,"150 250 m 150 350 l S");
//Get the stream length
ASUns32 streamLength = (ASUns32)strlen(buf);
//Create a CosObj object that represents the stream length
CosObj LengthEntry = CosNewInteger(cd, false,streamLength);
//Create a CosObj that represents a stream dictionary
//and sets its key-value pairs
CosObj AttrDict = CosNewDict(cd, false, 5);
char *Length_KStr = "Length";
CosDictPutKeyString(AttrDict, Length_KStr, LengthEntry);
//Determine if the stream dictionary is valid
if (CosObjEqual (AttrDict, CosNewNull ()) == true)
{
AVAlertNote ("The attributes dictionary could not be created.");
return;
}
Note:
This code example creates a
CosObj
object named
AttrDict
that represents a stream dictionary.
Inserting a Cos stream into a PDF document
When inserting a stream into a PDF document, ensure that the stream is valid; otherwise, a run-time error
occurs. This section explains how to create a stream that draws a thin black line segment and then inserts
the stream into the current PDF page. To insert a stream into the current PDF document page, perform the
following tasks:
1. Create a
PDPage
object that represents the current PDF page. For information, see
“Creating a
PDEContent object” on page 125
.
2. Create a
CosDoc
object that represents a PDF file by invoking the
PDDocGetCosDoc
method.
3. Define the stream that draws a thin black line segment. You can populate a character array with a
stream by invoking the
sprintf
method.
4. Create an
ASUns32
object that represents the stream length.