lib/origami/pdf.rb in origami-1.2.5 vs lib/origami/pdf.rb in origami-1.2.6

- old
+ new

@@ -63,79 +63,10 @@ require 'origami/parsers/pdf' module Origami - VERSION = "1.2.5" - REVISION = "$Revision: rev 167/, 2013/01/28 11:59:28 $" #:nodoc: - - # - # Global options for Origami. - # - OPTIONS = - { - :enable_type_checking => true, # set to false to disable type consistency checks during compilation. - :enable_type_guessing => true, # set to false to prevent the parser to guess the type of special dictionary and streams (not recommended). - :use_openssl => true # set to false to use Origami crypto backend. - } - - begin - require 'openssl' - OPTIONS[:use_openssl] = true - rescue LoadError - OPTIONS[:use_openssl] = false - end - - DICT_SPECIAL_TYPES = #:nodoc: - { - :Catalog => Catalog, - :Pages => PageTreeNode, - :Page => Page, - :Filespec => FileSpec, - :Action => Action, - :Font => Font, - :FontDescriptor => FontDescriptor, - :Encoding => Encoding, - :Annot => Annotation, - :Border => Annotation::BorderStyle, - :Outlines => Outline, - :OutputIntent => OutputIntent, - :Sig => Signature::DigitalSignature, - :SigRef => Signature::Reference, - :SigFieldLock => Field::SignatureLock, - :SV => Field::SignatureSeedValue, - :SVCert => Field::CertificateSeedValue, - :ExtGState => Graphics::ExtGState, - :RichMediaSettings => Annotation::RichMedia::Settings, - :RichMediaActivation => Annotation::RichMedia::Activation, - :RichMediaDeactivation => Annotation::RichMedia::Deactivation, - :RichMediaAnimation => Annotation::RichMedia::Animation, - :RichMediaPresentation => Annotation::RichMedia::Presentation, - :RichMediaWindow => Annotation::RichMedia::Window, - :RichMediaPosition => Annotation::RichMedia::Position, - :RichMediaContent => Annotation::RichMedia::Content, - :RichMediaConfiguration => Annotation::RichMedia::Configuration, - :RichMediaInstance => Annotation::RichMedia::Instance, - :RichMediaParams => Annotation::RichMedia::Parameters, - :CuePoint => Annotation::RichMedia::CuePoint - } - - STM_SPECIAL_TYPES = #:nodoc: - { - :ObjStm => ObjectStream, - :EmbeddedFile => EmbeddedFileStream, - :Metadata => MetadataStream, - :XRef => XRefStream, - :"3D" => U3DStream - } - - STM_XOBJ_SUBTYPES = #:nodoc: - { - :Image => Graphics::ImageXObject, - :Form => Graphics::FormXObject - } - class InvalidPDFError < Exception #:nodoc: end # # Main class representing a PDF file and its inner contents. @@ -199,10 +130,11 @@ def create(output, options = {}) pdf = PDF.new yield(pdf) if block_given? pdf.save(output, options) end + alias write create # # Deserializes a PDF dump. # def deserialize(filename) @@ -303,11 +235,11 @@ fd.write output(options) fd.close self end - alias saveas save + alias write save # # Saves the file up to given revision number. # This can be useful to visualize the modifications over different incremental updates. # _revision_:: The revision number to save. @@ -678,9 +610,17 @@ end end alias :[] :get_object + + def cast_object(reference, type) #:nodoc: + @revisions.each do |rev| + if rev.body.include?(reference) and type < rev.body[reference].class + rev.body[reference] = rev.body[reference].cast_to(type) + end + end + end # # Returns a new number/generation for future object. # def alloc_new_object_number