Module: Prawn::Document::Internals
- Included in:
- Prawn::Document
- Defined in:
- lib/prawn/document/internals.rb
Overview
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.
Instance Method Summary collapse
-
#add_content(str) ⇒ Object
Appends a raw string to the current page content.
-
#names ⇒ Object
The Name dictionary (PDF spec 3.6.3) for this document.
-
#page_fonts ⇒ Object
The Font dictionary for the current page.
-
#page_resources ⇒ Object
The Resources dictionary for the current page.
-
#page_xobjects ⇒ Object
The XObject dictionary for the current page.
-
#proc_set(*types) ⇒ Object
Add a new type to the current pages ProcSet.
-
#ref(data, &block) ⇒ Object
Creates a new Prawn::Reference and adds it to the Document’s object list.
Instance Method Details
#add_content(str) ⇒ Object
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
37 38 39 |
# File 'lib/prawn/document/internals.rb', line 37 def add_content(str) @page_content << str << "\n" end |
#names ⇒ Object
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.
68 69 70 |
# File 'lib/prawn/document/internals.rb', line 68 def names @root.data[:Names] ||= ref(:Type => :Names) end |
#page_fonts ⇒ Object
The Font dictionary for the current page
56 57 58 |
# File 'lib/prawn/document/internals.rb', line 56 def page_fonts page_resources[:Font] ||= {} end |
#page_resources ⇒ Object
The Resources dictionary for the current page
50 51 52 |
# File 'lib/prawn/document/internals.rb', line 50 def page_resources @current_page.data[:Resources] ||= {} end |
#page_xobjects ⇒ Object
The XObject dictionary for the current page
61 62 63 |
# File 'lib/prawn/document/internals.rb', line 61 def page_xobjects page_resources[:XObject] ||= {} end |
#proc_set(*types) ⇒ Object
Add a new type to the current pages ProcSet
43 44 45 46 |
# File 'lib/prawn/document/internals.rb', line 43 def proc_set(*types) @current_page.data[:ProcSet] ||= ref([]) @current_page.data[:ProcSet].data |= types end |
#ref(data, &block) ⇒ Object
Creates a new Prawn::Reference and adds it to the Document’s object list. The data
argument is anything that Prawn::PdfObject() can convert.
If a block is given, it will be invoked just before the object is written out to the PDF document stream. This allows you to do deferred processing on some references (such as fonts, which you might know all the details about until the last page of the document is finished).
25 26 27 |
# File 'lib/prawn/document/internals.rb', line 25 def ref(data, &block) @objects.push(Prawn::Reference.new(@objects.size + 1, data, &block)).last end |