lib/prawn/core/object_store.rb
# takes a source PDF and uses it as a template for this document.
#
takes a source PDF and uses it as a template for this document.
takes a source PDF and uses it as a template for this document .
def load_file(template)
        unless (template.respond_to?(:seek) && template.respond_to?(:read)) ||
               File.file?(template)
          raise ArgumentError, "#{template} does not exist"
        end
        hash = PDF::Reader::ObjectHash.new(template)
        src_info = hash.trailer[:Info]
        src_root = hash.trailer[:Root]
        @min_version = hash.pdf_version.to_f
        if hash.trailer[:Encrypt]
          msg = "Template file is an encrypted PDF, it can't be used as a template"
          raise Prawn::Errors::TemplateError, msg
        end
        if src_info
          @info = load_object_graph(hash, src_info).identifier
        end
        if src_root
          @root = load_object_graph(hash, src_root).identifier
        end
      rescue PDF::Reader::MalformedPDFError, PDF::Reader::InvalidObjectError
        msg = "Error reading template file. If you are sure it's a valid PDF, it may be a bug."
        raise Prawn::Errors::TemplateError, msg
      rescue PDF::Reader::UnsupportedFeatureError
        msg = "Template file contains unsupported PDF features"
        raise Prawn::Errors::TemplateError, msg
      end
def load_file ( template ) unless ( template . respond_to? ( :seek ) && template . respond_to? ( :read ) ) || File . file? ( template ) raise ArgumentError , "#{template} does not exist" end hash = PDF :: Reader :: ObjectHash . new ( template ) src_info = hash . trailer [ :Info ] src_root = hash . trailer [ :Root ] @min_version = hash . pdf_version . to_f if hash . trailer [ :Encrypt ] msg = "Template file is an encrypted PDF, it can't be used as a template" raise Prawn :: Errors :: TemplateError , msg end if src_info @info = load_object_graph ( hash , src_info ) . identifier end if src_root @root = load_object_graph ( hash , src_root ) . identifier end rescue PDF :: Reader :: MalformedPDFError , PDF :: Reader :: InvalidObjectError msg = "Error reading template file. If you are sure it's a valid PDF, it may be a bug." raise Prawn :: Errors :: TemplateError , msg rescue PDF :: Reader :: UnsupportedFeatureError msg = "Template file contains unsupported PDF features" raise Prawn :: Errors :: TemplateError , msg end
takes a source PDF and uses it as a template for this document.
takes a source PDF and uses it as a template for this document .
template