PrawnEx.PDF.Objects (prawn_ex v0.3.0)

Copy Markdown View Source

Builds PDF indirect object definitions (catalog, pages, page, stream).

Summary

Functions

Catalog: root of the document. References the Pages tree.

Image XObject: stream dict + data.

Returns the PDF fragment for an indirect object: "n 0 obj ... endobj"

Link annotation: /Type /Annot /Subtype /Link /Rect [ llx lly urx ury ] /A << /S /URI /URI (url) >>

Single page: /Type /Page, /Parent, /MediaBox, /Contents, /Resources. Optional /Annots.

Pages tree: /Type /Pages, /Count n, /Kids [id1 0 R, id2 0 R, ...]

Resources dict with built-in font(s). font_names: list of e.g. ["Helvetica", "Times-Bold"]. Emits /F1, /F2, ... for each. Empty list defaults to ["Helvetica"].

Resources dict with fonts and XObject refs. xobject_refs: [{"Im1", 7}] -> /Im1 7 0 R

Stream object body: dictionary + stream data. Caller adds "n 0 obj " and "endobj".

Functions

catalog(pages_id)

Catalog: root of the document. References the Pages tree.

image_xobject(width, height, data, list)

Image XObject: stream dict + data.

  • filter: :dctdata is a full JPEG bitstream (/DCTDecode).
  • filter: :flatedata is raw top-to-bottom RGB pixels (/FlateDecode).

indirect(id, body)

Returns the PDF fragment for an indirect object: "n 0 obj ... endobj"

page(parent_id, contents_id, media_box, resources, annot_refs \\ [])

Single page: /Type /Page, /Parent, /MediaBox, /Contents, /Resources. Optional /Annots.

pages_tree(kid_ids)

Pages tree: /Type /Pages, /Count n, /Kids [id1 0 R, id2 0 R, ...]

resources_fonts(font_names)

Resources dict with built-in font(s). font_names: list of e.g. ["Helvetica", "Times-Bold"]. Emits /F1, /F2, ... for each. Empty list defaults to ["Helvetica"].

resources_fonts_and_xobject(font_names, xobject_refs)

Resources dict with fonts and XObject refs. xobject_refs: [{"Im1", 7}] -> /Im1 7 0 R

stream_dict_and_data(data)

Stream object body: dictionary + stream data. Caller adds "n 0 obj " and "endobj".