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

Inherits:
Origami::XFA::Element show all
Defined in:
lib/origami/xfa/pdf.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.



31
32
33
34
35
# File 'lib/origami/xfa/pdf.rb', line 31

def initialize
  super("pdf")

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

Instance Method Details

#enclose_pdf(pdfdata) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/origami/xfa/pdf.rb', line 37

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



59
60
61
62
63
64
# File 'lib/origami/xfa/pdf.rb', line 59

def enclosed_pdf
  return nil unless has_enclosed_pdf?

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

#has_enclosed_pdf?Boolean

Returns:



49
50
51
52
53
# File 'lib/origami/xfa/pdf.rb', line 49

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

  !chunk.nil? and !chunk.text.nil?
end

#remove_enclosed_pdfObject



55
56
57
# File 'lib/origami/xfa/pdf.rb', line 55

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