PaperForge.Stream (PaperForge v0.2.0)

Copy Markdown View Source

Represents a PDF stream object.

A stream contains:

  • a PDF dictionary;
  • the raw stream data;
  • an optional list of filters.

The serializer is responsible for applying the filters, calculating /Length, and adding the corresponding /Filter entry.

Example

%PaperForge.Stream{
  dictionary: %{},
  data: "BT /F1 12 Tf ET",
  filters: [:flate]
}

Summary

Functions

Adds a filter to a stream.

Creates a new PDF stream.

Adds or replaces a dictionary entry.

Replaces the stream data.

Replaces the stream dictionary.

Returns the unfiltered stream data as a binary.

Types

filter()

@type filter() :: :flate

t()

@type t() :: %PaperForge.Stream{
  data: iodata(),
  dictionary: map(),
  filters: [filter()]
}

Functions

add_filter(stream, filter)

@spec add_filter(t(), filter()) :: t()

Adds a filter to a stream.

Duplicate filters are not added.

Example

stream =
  stream
  |> PaperForge.Stream.add_filter(:flate)

new(data, options \\ [])

@spec new(
  iodata(),
  keyword()
) :: t()

Creates a new PDF stream.

Supported options:

  • :dictionary
  • :filters

Examples

PaperForge.Stream.new(
  "Hello PDF"
)

PaperForge.Stream.new(
  "Compressed content",
  filters: [:flate]
)

PaperForge.Stream.new(
  jpeg_binary,
  dictionary: %{
    "Type" => {:name, "XObject"},
    "Subtype" => {:name, "Image"},
    "Filter" => {:name, "DCTDecode"}
  }
)

put(stream, key, value)

@spec put(t(), binary() | atom(), term()) :: t()

Adds or replaces a dictionary entry.

put_data(stream, data)

@spec put_data(t(), iodata()) :: t()

Replaces the stream data.

put_dictionary(stream, dictionary)

@spec put_dictionary(t(), map()) :: t()

Replaces the stream dictionary.

raw_data(stream)

@spec raw_data(t()) :: binary()

Returns the unfiltered stream data as a binary.