-1
for none, error, or other special meaning typedef
ASInt32
CosByteMax
;
typedef
ASEnum8
CosStreamOpenMode
;
typedef
ASInt32
CosStreamStartAndCode
;
Creates a new Cos stream, using data from an existing ASStm
. The data is copied, so the source stream may be closed after CosNewStream returns.
This method creates a Cos stream object by writing its PDF representation to an intermediate file in this format:
<
<
/Length
...
/Filter
...
/DecodeParms
...
>
>
stream
...
data,
possibly
encoded
...
endstream
See the description of the Stream Objects in "Objects," in ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 7.3.8, page 19. You can find this document on the web store of the International Standards Organization (ISO).
This occurs in four steps:
Step 1: Writing the attribute dictionary
If attributesDict
is a valid Cos dictionary, the method writes that dictionary to the intermediate file. Otherwise, it creates a new direct dictionary, determining a Length
key according to the sourceLength
value:
sourceLength
is negative, or if the source data is to be encoded (see below), the value of the Length
key is a reference to a new indirect object, whose value will be set in Step 4.Length
is a direct scalar representing sourceLength
.
The dictionary that is written becomes the new stream's attribute dictionary.
Step 2: Reading the data
sourceStart
determines where in the source stream to begin reading, and whether the source is seekable.
sourceStart
is a negative number, the source is assumed to be non-seekable but positioned at the point where reading should start.sourceStart
. If sourceStart
is zero, data is read from the beginning of the source stream. Positive values for sourceStart
may be used, for instance, to skip over initial data in the stream.
Step 3: Encoding the data
If attributesDict
is a valid Cos dictionary, it contains a Filter
key, and encodeTheSourceData
is true
, the method encodes the data after reading it from the source stream and before writing it to the intermediate file.
The attributesDict
is used as the new stream's dictionary. The Filter
entry in this dictionary indicates how the data in the resulting Cos stream object will be subsequently decoded; the value may be the name of a decoding filter or an array of such names. Specify multiple filters in the order they should be applied to decode the data (if parameters are needed to decode the data, they are specified as the value of the DecodeParms
key in attributesDict
. See the description of the DecodeParms attribute in Table 5 in ISO 32000-1:2008, Document Management-Portable Document Format- Part 1: PDF 1.7, section 7.3.8.2, page 20. You can find this document on the web store of the International Standards Organization (ISO).
For each decoding filter, there is a corresponding encoding filter, which the method applies to the source data during this step.
If parameters are needed to encode the data, they must be specified in the call by encodeParms
(the encoding parameters are often different from the decoding parameters). The encodeParms
parameter is optional for all encoding filters except DCTDecode
and JBIG2Decode
. See the encodeParms
field of PDEFilterSpec
.
If an array of filters is supplied, and at least one of them requires encoding parameters, then a corresponding array of encoding parameters is also required. Use the NULL
object to represent default parameters for filters that have defaults.
In any other case, the method copies the source data directly into the Cos stream with no encoding. If sourceLength
is negative, it reads bytes until the source reaches its EOF. Otherwise, sourceLength
indicates how many bytes to read from the source, and an exception is raised if the source reaches EOF before that.
Step 4: Writing the data
After the data is written, if the value of the Length
key in the attributes dictionary was an indirect reference (either because it was supplied that way in attributesDict
, or because it was created that way in Step 1, the value of that indirect object is set to the number of bytes actually written (that is, the encoded length if the data was encoded). An indirect Length
key is useful for one-pass writing, when the size of the written data is not known in advance, either because the data was to be encoded, or because there was no way to know how much data there would be before the source reached its EOF.
An exception is raised if attributesDict
is neither the NULL
object nor a direct Cos dictionary, sourceStart
is nonnegative but the source is not seekable, or if sourceLength
is nonnegative but the source stream reaches EOF before that many bytes have been read.
For attributeDict, see the description of Stream Objects in the ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 9.9, page 288. You can find this document on the web store of the International Standards Organization (ISO).
Note: CosNewStream() sets the document PDDocNeedsSave
flag (see PDDocFlags).
Note: You cannot call CosStreamPos
()
on a stream created with CosNewStream
()
until the file has been saved.
CosObj
CosNewStream(
CosDoc
dP
,
ASBool
indirect
,
ASStm
stm
,
CosStreamStartAndCode
sourceStart
,
ASBool
encodeTheSourceData
,
CosObj
attributesDict
,
CosObj
encodeParms
,
CosByteMax
sourceLength
);
dP | The Cos document in which the newly created stream will be used.
|
indirect | Must always be
true , specifying that the Cos stream is created as an indirect object (all streams are indirect). This also sets the document's PDDocNeedsSave flag (see PDDocFlags ). |
stm |
stm after CosNewStream () returns. The source stream can be any readable ASStm . Typical sources are: |
sourceStart | The byte offset into
stm from which data reading starts for a seekable stream. If the value is negative, it specifies that the stream is not seekable. |
encodeTheSourceData | Determines whether the data in
stm should be encoded using filters specified in attributesDict before it is written to the Cos stream. See the description of the encoding step above. If attributesDict is a NULL object or if the dictionary has no Filter key, this value is ignored. |
attributesDict | Either the
NULL Cos object, or a direct Cos dictionary containing stream attributes, such as the length of the Cos stream data and a list of decoding filters and parameters to apply to the data. See the description of the Stream Objects in "Objects" in ISO 32000-1:2008, Document Management-Portable Document Format-Part 1: PDF 1.7, section 7.3.8, page 19. See the encoding step in the description above. |
encodeParms | The parameters to be used by the filters if the source data is encoded before it is written to the file. The parameters follow the structure for the value of the You can find this document on the web store of the International Standards Organization (ISO). See the encoding step in the description above. If no encoding parameters are needed, this value is ignored. |
sourceLength | The amount of data to be read from the source. If negative (typically
-1 ), data is read from the source until it reaches its EOF. See Step 1 in the description above. |
Creates a new Cos stream, using data from an existing ASStm
. For details, see CosNewStream
()
.
This is the same as CosNewStream
()
, except that decodeLength
is a 64-bit value instead of a 32-bit value, and allowDelayedRead
enables the implementation to avoid making an intermediate copy of the stream data. This is useful when creating very large streams of data.
CosObj
CosNewStream64(
CosDoc
dP
,
ASBool
indirect
,
ASStm
stm
,
ASInt64
stmStartPos
,
ASBool
stmDataIsDecoded
,
CosObj
attributesDict
,
CosObj
encodeParms
,
ASInt64
sourceLength
,
ASBool
allowDelayedRead
);
dP | The Cos document in which the newly created stream will be used.
|
indirect | Must always be
true , specifying that the Cos stream is created as an indirect object. |
stm | The source stream containing the data to copy into the new stream.
|
stmStartPos | Starting position for the stream. Its default is
0 . |
stmDataIsDecoded | A boolean value indicating whether the data in
stm should be encoded using filters specified in attributesDict . |
attributesDict | Either the
NULL Cos object, or a direct Cos dictionary containing stream attributes. |
encodeParms | The parameters to be used by the filters if the source data is to be encoded.
|
sourceLength | The amount of data to be read from the source.
|
allowDelayedRead | If this is Important: In this case, the caller must not close
If |
CosObj
CosStreamDict(
CosObj
stream
);
stream | IN/OUT The stream whose attributes dictionary is obtained.
|
Gets the length of a Cos stream from the Length
key in the stream's attributes dictionary. This specifies the length of the undecoded data, which is the number of bytes in the stream before the Filter
(if any) is applied.
This has the same effect as calling CosIntegerValue
(CosDictGetKeyString(stream,
"Length"))
.
An exception is raised if the Length
key is not found in the attributes dictionary, if its value is not an integer, or if its value is outside the range of 32-bit integers.
ASTArraySize
CosStreamLength(
CosObj
stream
);
stream | The stream whose length is obtained.
|
Gets the length of a Cos stream from the Length
key in the stream's attributes dictionary. See CosStreamLength
()
for details. This is the same as CosStreamLength
()
, except that the return value is a 64-bit integer instead of a 32-bit integer.
This has the same effect as calling CosInteger64Value
(CosDictGetKeyString(stream,
"Length"))
An exception is raised if the Length key is not found in the attributes dictionary, or if its value is not an integer.
ASInt64
CosStreamLength64(
CosObj
stream
);
stream | The stream whose length is obtained.
|
ASStm
for reading data from a Cos stream. The data in the Cos stream may be filtered and encrypted. After opening the Cos stream, data can be read from it into memory using ASStmRead
()
. When reading is completed, close the stream using ASStmClose
()
. ASStm
CosStreamOpenStm(
CosObj
stream
,
CosStreamOpenMode
mode
);
stream | The Cos stream object for which an
ASStm is opened. |
mode | This must be one of the
CosStreamOpenMode values. |
ASStm
.
Gets the byte offset of the start of a Cos stream's data in the PDF file (which is the byte offset of the beginning of the line following the stream
token). Use this method to obtain the file location of any private data in a stream that you need to read directly rather than letting it pass through the normal Cos mechanisms. For example, this could apply to a QuickTime video embedded in a PDF file.
CosStreamPos
()
is only valid when called on a stream that is already stored in a PDF document. If the stream was created using CosNewStream
()
, the new stream is stored in the document's temp file, and you cannot invoke CosStreamPos
()
on it. After the file has been saved, you can use CosStreamPos
()
on the stream.
ASTCount
CosStreamPos(
CosObj
stream
);
stream | The stream whose current position is obtained.
|
is raised if the stream object has not yet been saved to the PDF file. In other words, before you can call
CosStreamPos () on a newly created stream, you must first save the PDF file. |
CosStreamPos
()
. This is the same as CosStreamPos
()
, except that the return value is a 64-bit file position instead of a 32-bit file position. ASFilePos64
CosStreamPos64(
CosObj
stream
);
stream | The stream whose current position is obtained.
|
is raised if the stream object has not yet been saved to the PDF file.
|