### Home Classes Methods

### In Files

- lib/prawn/document/internals.rb

### Methods

- #add_content
- #before_render
- #deref
- #names
- #names?
- #on_page_create
- #ref
- #ref!

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Configurable
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::GridBox
- Prawn::Document::Internals
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::FontMetricCache
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Patterns
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::ImageHandler
- Prawn::Images
- Prawn::Images::Image
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::SoftMask
- Prawn::Stamp
- Prawn::SynchronizedCache
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::Image
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::SpanDummy
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Table::ColumnWidthCalculator
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Prawn::ThreadLocalCache
- PDF
- PDF::Core
- PDF::Core::Reference
- PDF::Core::Stream
- Arcfour
- Numeric

No matching classes.

# Prawn::Document::Internals

This module exposes a few low-level PDF features for those who want to extend Prawn's core functionality. If you are not comfortable with low level PDF functionality as defined by Adobe's specification, chances are you won't need anything you find here.

@private

### Public Instance Methods

add_content(str) click to toggle source

Appends a raw string to the current page content.

    # Raw line drawing example:
    x1,y1,x2,y2 = 100,500,300,550
    pdf.add_content("%.3f %.3f m" % [ x1, y1 ])  # move
    pdf.add_content("%.3f %.3f l" % [ x2, y2 ])  # draw path
    pdf.add_content("S") # stroke

    # File lib/prawn/document/internals.rb, line 55
    def add_content(str)
      save_graphics_state if graphic_state.nil?
      state.page.content << str << "\n"
    end

before_render(&block) click to toggle source

Defines a block to be called just before the document is rendered.

    # File lib/prawn/document/internals.rb, line 76
    def before_render(&block)
      state.before_render_callbacks << block
    end

deref(obj) click to toggle source

At any stage in the object tree an object can be replaced with an indirect reference. To get access to the object safely, regardless of if it's hidden behind a Prawn::Reference, wrap it in deref().

    # File lib/prawn/document/internals.rb, line 43
    def deref(obj)
      obj.is_a?(PDF::Core::Reference) ? obj.data : obj
    end

names() click to toggle source

The Name dictionary (PDF spec 3.6.3) for this document. It is lazily initialized, so that documents that do not need a name dictionary do not incur the additional overhead.

    # File lib/prawn/document/internals.rb, line 64
    def names
      state.store.root.data[:Names] ||= ref!(:Type => :Names)
    end

names?() click to toggle source

Returns true if the Names dictionary is in use for this document.

    # File lib/prawn/document/internals.rb, line 70
    def names?
      state.store.root.data[:Names]
    end

on_page_create(&block) click to toggle source

Defines a block to be called just before a new page is started.

    # File lib/prawn/document/internals.rb, line 82
    def on_page_create(&block)
       if block_given?
          state.on_page_create_callback = block
       else
          state.on_page_create_callback = nil
       end
    end

ref(data) click to toggle source

Creates a new Prawn::Reference and adds it to the Document's object list. The `data` argument is anything that Prawn::PdfObject() can convert.

Returns the identifier which points to the reference in the ObjectStore

    # File lib/prawn/document/internals.rb, line 23
    def ref(data)
      ref!(data).identifier
    end

ref!(data) click to toggle source

Like ref, but returns the actual reference instead of its identifier.

While you can use this to build up nested references within the object tree, it is recommended to persist only identifiers, and them provide helper methods to look up the actual references in the ObjectStore if needed. If you take this approach, Prawn::Document::Snapshot will probably work with your extension

    # File lib/prawn/document/internals.rb, line 35
    def ref!(data)
      state.store.ref(data)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.