lib/hexapdf/document.rb in hexapdf-0.19.3 vs lib/hexapdf/document.rb in hexapdf-0.20.0

- old
+ new

@@ -34,10 +34,11 @@ # commercial licenses are available at <https://gettalong.at/hexapdf/>. #++ require 'stringio' require 'hexapdf/error' +require 'hexapdf/data_dir' require 'hexapdf/content' require 'hexapdf/configuration' require 'hexapdf/reference' require 'hexapdf/object' require 'hexapdf/pdf_array' @@ -102,10 +103,11 @@ autoload(:Pages, 'hexapdf/document/pages') autoload(:Fonts, 'hexapdf/document/fonts') autoload(:Images, 'hexapdf/document/images') autoload(:Files, 'hexapdf/document/files') + autoload(:Signatures, 'hexapdf/document/signatures') # :call-seq: # Document.open(filename, **docargs) -> doc # Document.open(filename, **docargs) {|doc| block} -> obj # @@ -613,9 +615,33 @@ # # * Once the #encrypt method is called, the specified security handler for encrypting is # returned. def security_handler @security_handler + end + + # Returns +true+ if the document is signed, i.e. contains digital signatures. + def signed? + acro_form&.signature_flag?(:signatures_exist) + end + + # Returns an array with the digital signatures of this document. + def signatures + @signatures ||= Signatures.new(self) + end + + # Signs the document and writes it to the given file or IO object. + # + # For details on the arguments +file_or_io+, +signature+ and +write_options+ see + # HexaPDF::Document::Signatures#add. + # + # The signing handler to be used is determined by the +handler+ argument together with the rest + # of the keyword arguments (see HexaPDF::Document::Signatures#handler for details). + # + # If not changed, the default signing handler is HexaPDF::Document::Signatures::DefaultHandler. + def sign(file_or_io, handler: :default, signature: nil, write_options: {}, **handler_options) + handler = signatures.handler(name: handler, **handler_options) + signatures.add(file_or_io, handler, signature: signature, write_options: write_options) end # Validates all objects, or, if +only_loaded+ is +true+, only loaded objects, with optional # auto-correction, and returns +true+ if everything is fine. #