Module: Prawn
- Defined in:
- lib/prawn/errors.rb,
lib/prawn.rb,
lib/prawn/images.rb,
lib/prawn/document.rb,
lib/prawn/graphics.rb,
lib/prawn/font/cmap.rb,
lib/prawn/reference.rb,
lib/prawn/images/jpg.rb,
lib/prawn/images/png.rb,
lib/prawn/pdf_object.rb,
lib/prawn/font/metrics.rb,
lib/prawn/document/text.rb,
lib/prawn/font/wrapping.rb,
lib/prawn/graphics/cell.rb,
lib/prawn/document/table.rb,
lib/prawn/document/bounding_box.rb,
lib/prawn/document/page_geometry.rb
Overview
page_geometry.rb : Describes PDF page geometries
Copyright April 2008, Gregory Brown. All Rights Reserved.
This is free software. Please see the LICENSE and COPYING files for details.
Defined Under Namespace
Modules: Errors, Font, Graphics, Images Classes: Document, Reference
Constant Summary collapse
- BASEDIR =
The base source directory for Prawn as installed on the system
File.(File.join(dir, '..'))
Class Method Summary collapse
-
.PdfObject(obj, in_content_stream = false) ⇒ Object
Serializes Ruby objects to their PDF equivalents.
-
.Reference(*args) ⇒ Object
:nodoc:.
Class Method Details
.PdfObject(obj, in_content_stream = false) ⇒ Object
Serializes Ruby objects to their PDF equivalents. Most primitive objects will work as expected, but please note that Name objects are represented by Ruby Symbol objects and Dictionary objects are represented by Ruby hashes (keyed by symbols)
Examples:
PdfObject(true) #=> "true"
PdfObject(false) #=> "false"
PdfObject(1.2124) #=> "1.2124"
PdfObject("foo bar") #=> "(foo bar)"
PdfObject(:Symbol) #=> "/Symbol"
PdfObject(["foo",:bar, [1,2]]) #=> "[foo /bar [1 2]]"
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/prawn/pdf_object.rb', line 27 def PdfObject(obj, in_content_stream = false) #:nodoc: case(obj) when NilClass then "null" when TrueClass then "true" when FalseClass then "false" when Numeric then String(obj) when Array "[" << obj.map { |e| PdfObject(e, in_content_stream) }.join(' ') << "]" when String obj = "\xFE\xFF" + obj.unpack("U*").pack("n*") unless in_content_stream "<" << obj.unpack("H*").first << ">" when Symbol if (obj = obj.to_s) =~ /\s/ raise Prawn::Errors::FailedObjectConversion, "A PDF Name cannot contain whitespace" else "/" << obj end when Hash output = "<< " obj.each do |k,v| unless String === k || Symbol === k raise Prawn::Errors::FailedObjectConversion, "A PDF Dictionary must be keyed by names" end output << PdfObject(k.to_sym, in_content_stream) << " " << PdfObject(v, in_content_stream) << "\n" end output << ">>" when Prawn::Reference obj.to_s else raise Prawn::Errors::FailedObjectConversion, "This object cannot be serialized to PDF" end end |
.Reference(*args) ⇒ Object
:nodoc:
43 44 45 |
# File 'lib/prawn/reference.rb', line 43 def Reference(*args) #:nodoc: Reference.new(*args) end |