Class: Origami::XDP::Packet::PDF

Inherits:
Origami::XFA::Element show all
Defined in:
lib/origami/xfa.rb

Overview

An XDF pdf element encloses a PDF packet.

Instance Method Summary collapse

Methods included from Origami::XFA

included

Constructor Details

#initializePDF

Returns a new instance of PDF.



822
823
824
825
826
# File 'lib/origami/xfa.rb', line 822

def initialize
  super("pdf")

  add_attribute 'xmlns', 'http://ns.adobe.com/xdp/pdf/'
end

Instance Method Details

#enclose_pdf(pdfdata) ⇒ Object



828
829
830
831
832
833
834
835
836
837
838
# File 'lib/origami/xfa.rb', line 828

def enclose_pdf(pdfdata)
  require 'base64'
  b64data = Base64.encode64(pdfdata).chomp!
 
  doc = elements['document'] || add_element('document')
  chunk = doc.elements['chunk'] || doc.add_element('chunk')

  chunk.text = b64data

  self
end

#enclosed_pdfObject



850
851
852
853
854
855
# File 'lib/origami/xfa.rb', line 850

def enclosed_pdf
  return nil unless has_enclosed_pdf?

  require 'base64'
  Base64.decode64(elements['document/chunk'].text)
end

#has_enclosed_pdf?Boolean

Returns:



840
841
842
843
844
# File 'lib/origami/xfa.rb', line 840

def has_enclosed_pdf?
  chunk = elements['document/chunk']

  not chunk.nil? and not chunk.text.nil?
end

#remove_enclosed_pdfObject



846
847
848
# File 'lib/origami/xfa.rb', line 846

def remove_enclosed_pdf
  elements.delete('document') if has_enclosed_pdf?
end