PrawnEx.PDF.Objects (prawn_ex v0.6.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.

ExtGState dict carrying constant fill + stroke alpha.

FontDescriptor for an embedded TrueType font. metrics comes from PrawnEx.Font.TrueType.parse/1.

Embedded TrueType font program: /FontFile2 stream, flate-compressed.

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".

Simple /TrueType font dict with WinAnsi encoding and explicit widths.

Functions

catalog(pages_id)

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

ext_gstate(alpha)

ExtGState dict carrying constant fill + stroke alpha.

font_descriptor(base_name, metrics, font_file_id)

FontDescriptor for an embedded TrueType font. metrics comes from PrawnEx.Font.TrueType.parse/1.

font_file2(ttf_data)

Embedded TrueType font program: /FontFile2 stream, flate-compressed.

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(font_entries, xobject_refs \\ [], gs_refs \\ [])

General resources dict.

font_entries[{"F1", {:base14, "Helvetica"}} | {"F2", {:ref, id}}] xobject_refs[{"Im1", id}]; gs_refs[{"GS1", id}].

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".

truetype_font(base_name, widths, descriptor_id)

Simple /TrueType font dict with WinAnsi encoding and explicit widths.