
Adobe Acrobat SDK
Working with Cos Objects
Developing Plug-ins and Applications
Creating Cos streams 191
In addition, most filters are defined so that the data is self-limiting; that is, they use an encoding scheme in
which an explicit end-of-data (EOD) marker delimits the extent of the data. Finally, streams are used to
represent many objects from whose length attributes can be inferred. All of these constraints must be
consistent.
For example, an image with 10 rows and 20 columns, using a single color component and 8 bits per
component, requires exactly 200 bytes of image data. If the stream uses a filter, there must be enough
bytes of encoded data in the PDF file to produce those 200 bytes. An error occurs if the
Length
entry is
too small, if an explicit EOD marker occurs too soon, or if the decoded data does not contain 200 bytes. It is
also an error if the stream contains too much data, with the exception that there may be an extra
end-of-line marker in the PDF file before the
endstream
keyword. All streams created in this section have
a stream dictionary defined.
For each stream that you want to insert into a PDF document, create a stream dictionary that contains at
least the
Length
entry, as shown in the following example:
<</Length 100>>
To create a stream dictionary with the
Length
entry defined, perform the following tasks:
1. Create a
CosDoc
object that represents a PDF file by invoking the
PDDocGetCosDoc
method.
2. Create an
ASUns32
object that represents the stream length.
3. Create a
CosObj
object that represents the length of the stream by invoking the
CosNewInteger
method and passing the following arguments:
●
A
CosDoc
object that you created in step 1.
●
An
ASBool
object that specifies whether the
CosObj
object is an indirect or direct object. If
true
,
the string is an indirect object. If
false
, the string is a direct object. For information, see
“About
direct and indirect objects” on page 179
.
●
The
ASUns32
object created in step 2 that represents the stream length.
The
CosNewInteger
method returns a
CosObj
object that represents the stream length.
4. Create a
CosObj
object that represents the Cos dictionary. For information, see
“Creating Cos
dictionaries” on page 186
.
5. Set the stream dictionary key and value by invoking the
CosDictPutKeyString
method and
passing the following arguments:
●
The
CosObj
object that you created in step 4 that represents the dictionary.
●
A character pointer that specifies the name of the key, which in this situation is
Length
.
●
The
CosObj
object created in step 3 that specifies the length of the stream.
The following code example creates a stream dictionary. The first part of this code example creates a
PDPage
object by using an
AVDoc
object. For information about this application logic, see
“Creating a
PDEContent object” on page 125
.