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.



34
35
36
37
38
# File 'lib/origami/xfa/pdf.rb', line 34

def initialize
    super("pdf")

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

Instance Method Details

#enclose_pdf(pdfdata) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/origami/xfa/pdf.rb', line 40

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



62
63
64
65
66
67
# File 'lib/origami/xfa/pdf.rb', line 62

def enclosed_pdf
    return nil unless has_enclosed_pdf?

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

#has_enclosed_pdf?Boolean

Returns:



52
53
54
55
56
# File 'lib/origami/xfa/pdf.rb', line 52

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

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

#remove_enclosed_pdfObject



58
59
60
# File 'lib/origami/xfa/pdf.rb', line 58

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