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.



825
826
827
828
829
# File 'lib/origami/xfa.rb', line 825

def initialize
    super("pdf")

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

Instance Method Details

#enclose_pdf(pdfdata) ⇒ Object



831
832
833
834
835
836
837
838
839
840
841
# File 'lib/origami/xfa.rb', line 831

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



853
854
855
856
857
858
# File 'lib/origami/xfa.rb', line 853

def enclosed_pdf
    return nil unless has_enclosed_pdf?

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

#has_enclosed_pdf?Boolean

Returns:



843
844
845
846
847
# File 'lib/origami/xfa.rb', line 843

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

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

#remove_enclosed_pdfObject



849
850
851
# File 'lib/origami/xfa.rb', line 849

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