pdfmm 0.9.20
Public Member Functions | Static Public Attributes | Protected Member Functions | List of all members
mm::PdfStream Class Referenceabstract

#include <PdfStream.h>

Inheritance diagram for mm::PdfStream:
mm::PdfFileStream mm::PdfMemStream

Public Member Functions

virtual void Write (PdfOutputDevice &device, const PdfEncrypt *encrypt)=0
 
void Set (const std::string_view &view, const PdfFilterList &filters)
 
void Set (const char *buffer, size_t len, const PdfFilterList &filters)
 
void Set (const std::string_view &view)
 
void Set (const char *buffer, size_t len)
 
void Set (PdfInputStream &stream)
 
void Set (PdfInputStream &stream, const PdfFilterList &filters)
 
void SetRawData (PdfInputStream &stream, ssize_t len=-1)
 
void BeginAppend (bool clearExisting=true)
 
void BeginAppend (const PdfFilterList &filters, bool clearExisting=true, bool deleteFilters=true)
 
PdfStreamAppend (const std::string_view &view)
 
PdfStreamAppend (const char *buffer, size_t len)
 
void EndAppend ()
 
bool IsAppending () const
 
virtual size_t GetLength () const =0
 
virtual void GetCopy (std::unique_ptr< char[]> &buffer, size_t &len) const =0
 
virtual void GetCopy (PdfOutputStream &stream) const =0
 
void GetFilteredCopy (std::unique_ptr< char[]> &buffer, size_t &len) const
 
void GetFilteredCopy (PdfOutputStream &stream) const
 
const PdfStreamoperator= (const PdfStream &rhs)
 

Static Public Attributes

static enum PdfFilterType DefaultFilter
 

Protected Member Functions

 PdfStream (PdfObject &parent)
 
virtual const char * GetInternalBuffer () const =0
 
virtual size_t GetInternalBufferSize () const =0
 
virtual void BeginAppendImpl (const PdfFilterList &filters)=0
 
virtual void AppendImpl (const char *data, size_t len)=0
 
virtual void EndAppendImpl ()=0
 

Detailed Description

A PDF stream can be appended to any PdfObject and can contain arbitrary data.

Most of the time it will contain either drawing commands to draw onto a page or binary data like a font or an image.

You have to use a concrete implementation of a stream, which can be retrieved from a StreamFactory.

See also
PdfIndirectObjectList
PdfMemoryStream
PdfFileStream

Constructor & Destructor Documentation

◆ PdfStream()

PdfStream::PdfStream ( PdfObject parent)
protected

Create a new PdfStream object which has a parent PdfObject. The stream will be deleted along with the parent. This constructor will be called by PdfObject::Stream() for you.

Parameters
parentparent object

Member Function Documentation

◆ Append() [1/2]

PdfStream & PdfStream::Append ( const char *  buffer,
size_t  len 
)

Append a binary buffer to the current stream contents.

Make sure BeginAppend() has been called before.

Parameters
buffera buffer
lensize of the buffer
See also
BeginAppend
EndAppend

◆ Append() [2/2]

PdfStream & mm::PdfStream::Append ( const std::string_view &  view)

Append a binary buffer to the current stream contents.

Make sure BeginAppend() has been called before.

Parameters
viewa buffer
See also
BeginAppend
EndAppend

◆ AppendImpl()

virtual void mm::PdfStream::AppendImpl ( const char *  data,
size_t  len 
)
protectedpure virtual

Append a binary buffer to the current stream contents.

Parameters
dataa buffer
lenlength of the buffer
See also
BeginAppend
Append
EndAppend

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ BeginAppend() [1/2]

void PdfStream::BeginAppend ( bool  clearExisting = true)

Start appending data to this stream.

This method has to be called before any of the append methods. All appended data will be Flate-encoded.

Parameters
bClearExistingif true any existing stream contents will be cleared.
See also
Append
EndAppend
eDefaultFilter

◆ BeginAppend() [2/2]

void PdfStream::BeginAppend ( const PdfFilterList &  filters,
bool  clearExisting = true,
bool  deleteFilters = true 
)

Start appending data to this stream. This method has to be called before any of the append methods.

Use PdfFilterFactory::CreateFilterList() if you want to use the contents of the stream dictionary's existing filter key.

Parameters
filtersa list of filters to use when appending data
bClearExistingif true any existing stream contents will be cleared.
bDeleteFiltersif true existing filter keys are deleted if an empty list of filters is passed (required for SetRawData())
See also
Append
EndAppend

◆ BeginAppendImpl()

virtual void mm::PdfStream::BeginAppendImpl ( const PdfFilterList &  filters)
protectedpure virtual

Begin appending data to this stream. Clears the current stream contents.

Use PdfFilterFactory::CreateFilterList() if you want to use the contents of the stream dictionary's existing filter key.

Parameters
filtersuse these filters to encode any data written to the stream.

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ EndAppend()

void PdfStream::EndAppend ( )

Finish appending data to this stream. BeginAppend() has to be called before this method.

See also
BeginAppend
Append

◆ EndAppendImpl()

virtual void mm::PdfStream::EndAppendImpl ( )
protectedpure virtual

Finish appending data to the stream

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ GetCopy() [1/2]

virtual void mm::PdfStream::GetCopy ( PdfOutputStream stream) const
pure virtual

Get a copy of a the stream and write it to a PdfOutputStream

Parameters
streamdata is written to this stream.

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ GetCopy() [2/2]

virtual void mm::PdfStream::GetCopy ( std::unique_ptr< char[]> &  buffer,
size_t &  len 
) const
pure virtual

Get a malloc()'d buffer of the current stream. No filters will be applied to the buffer, so if the stream is Flate-compressed the compressed copy will be returned.

The caller has to the buffer.

Parameters
bufferpointer to the buffer
lenpointer to the buffer length

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ GetFilteredCopy() [1/2]

void PdfStream::GetFilteredCopy ( PdfOutputStream stream) const

Get a filtered copy of a the stream and write it to a PdfOutputStream

Parameters
streamfiltered data is written to this stream.

◆ GetFilteredCopy() [2/2]

void mm::PdfStream::GetFilteredCopy ( std::unique_ptr< char[]> &  buffer,
size_t &  len 
) const

Get a malloc()'d buffer of the current stream which has been filtered by all filters as specified in the dictionary's /Filter key. For example, if the stream is Flate-compressed, the buffer returned from this method will have been decompressed.

The caller has to the buffer.

Parameters
bufferpointer to the buffer
lenpointer to the buffer length

◆ GetInternalBuffer()

virtual const char * mm::PdfStream::GetInternalBuffer ( ) const
protectedpure virtual

Required for the GetFilteredCopy() implementation

Returns
a handle to the internal buffer

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ GetInternalBufferSize()

virtual size_t mm::PdfStream::GetInternalBufferSize ( ) const
protectedpure virtual

Required for the GetFilteredCopy() implementation

Returns
the size of the internal buffer

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ GetLength()

virtual size_t mm::PdfStream::GetLength ( ) const
pure virtual

Get the stream's length with all filters applied (e.g. if the stream is Flate-compressed, the length of the compressed data stream).

Returns
the length of the internal buffer

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

◆ IsAppending()

bool mm::PdfStream::IsAppending ( ) const
inline
Returns
true if code is between BeginAppend() and EndAppend() at the moment, i.e. it is safe to call EndAppend() now.
See also
BeginAppend
Append

◆ operator=()

const PdfStream & PdfStream::operator= ( const PdfStream rhs)

Create a copy of a PdfStream object

Parameters
rhsthe object to clone
Returns
a reference to this object

◆ Set() [1/6]

void PdfStream::Set ( const char *  buffer,
size_t  len 
)

Set a binary buffer as stream data. All data will be Flate-encoded.

Parameters
bufferbuffer containing the stream data
lenlength of the buffer

◆ Set() [2/6]

void PdfStream::Set ( const char *  buffer,
size_t  len,
const PdfFilterList &  filters 
)

Set a binary buffer as stream data.

Use PdfFilterFactory::CreateFilterList() if you want to use the contents of the stream dictionary's existing filter key.

Parameters
bufferbuffer containing the stream data
lenlength of the buffer
filtersa list of filters to use when appending data

◆ Set() [3/6]

void mm::PdfStream::Set ( const std::string_view &  view)

Set a binary buffer as stream data. All data will be Flate-encoded.

Parameters
viewbuffer containing the stream data

◆ Set() [4/6]

void mm::PdfStream::Set ( const std::string_view &  view,
const PdfFilterList &  filters 
)

Set a binary buffer as stream data.

Use PdfFilterFactory::CreateFilterList() if you want to use the contents of the stream dictionary's existing filter key.

Parameters
viewbuffer containing the stream data
filtersa list of filters to use when appending data

◆ Set() [5/6]

void PdfStream::Set ( PdfInputStream stream)

Set a binary buffer whose contents are read from a PdfInputStream All data will be Flate-encoded.

Parameters
streamread stream contents from this PdfInputStream

◆ Set() [6/6]

void PdfStream::Set ( PdfInputStream stream,
const PdfFilterList &  filters 
)

Set a binary buffer whose contents are read from a PdfInputStream

Use PdfFilterFactory::CreateFilterList() if you want to use the contents of the stream dictionary's existing filter key.

Parameters
streamread stream contents from this PdfInputStream
filtersa list of filters to use when appending data

◆ SetRawData()

void PdfStream::SetRawData ( PdfInputStream stream,
ssize_t  len = -1 
)

Sets raw data for this stream which is read from an input stream. This method does neither encode nor decode the read data. The filters of the object are not modified and the data is expected encoded as stated by the /Filters key in the stream's object.

Parameters
streamread data from this input stream
lenread exactly len bytes from the input stream, if len = -1 read until the end of the input stream was reached.

◆ Write()

virtual void mm::PdfStream::Write ( PdfOutputDevice device,
const PdfEncrypt encrypt 
)
pure virtual

Write the stream to an output device

Parameters
devicewrite to this outputdevice.
encryptencrypt stream data using this object

Implemented in mm::PdfFileStream, and mm::PdfMemStream.

Member Data Documentation

◆ DefaultFilter

enum PdfFilterType mm::PdfStream::DefaultFilter
static

The default filter to use when changing the stream content. It's a static member and applies to all newly created/changed streams. The default value is PdfFilterType::FlateDecode.