class

PDF::Objects::Stream

Inherits PDF::Objects::Base < Reference < Object

Represents a PDF stream object.

A stream consists of a dictionary followed by binary data. The dictionary must contain at least a /Length entry specifying the number of bytes in the stream data.

Streams are used for page content, images, fonts, and other binary data. They can be compressed using various filters.

stream = PDF::Objects::Stream.new
stream.data = "BT /F1 12 Tf 72 720 Td (Hello) Tj ET"
stream.to_pdf
# => "<</Length 38>>\nstream\nBT /F1 12 Tf 72 720 Td (Hello) Tj ET\nendstream"

Note: When used as an indirect object, the stream is typically compressed with FlateDecode for smaller file size.

Constructors

new(dictionary : Dictionary, data : Bytes = Bytes.empty)
Source

Instance methods

[](key : Name) : Base

Get a dictionary entry

Source
[](key : String) : Base
Source
[]=(key : Name, value : Base) : Base

Set a dictionary entry

Source
[]=(key : String, value : Base) : Base
Source
[]?(key : Name) : Base | Nil
Source
[]?(key : String) : Base | Nil
Source
add_filter(filter : Filters::Base) : self

Add a filter to the stream

Source
data

The raw stream data (before any encoding)

Source
data=(bytes : Bytes) : Bytes

Set data from bytes

Source
data=(content : String) : Bytes

Set data from a string

Source
dictionary

The stream dictionary containing metadata

Source
encoded_data

Get the encoded data (applies filters)

Source
to_pdf(io : IO) : Nil

Serializes this object to an IO.

By default, this writes the result of #to_pdf to the IO. Subclasses may override for more efficient streaming.

Source
to_pdf

Serializes this object to PDF syntax.

Returns the PDF representation as a string.

Source