Class: Prawn::Attachment::EmbeddedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/attachment/embedded_file.rb

Overview

EmbeddedFile represents a file to be embedded in the PDF.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, options = {}) ⇒ EmbeddedFile

Returns a new instance of EmbeddedFile.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/prawn/attachment/embedded_file.rb', line 9

def initialize(data, options = {})
  @data = data

  @creation_date = options[:creation_date]
  @creation_date = Time.now.utc unless @creation_date.is_a?(Time)

  @modification_date = options[:modification_date]
  @modification_date = Time.now.utc unless @modification_date.is_a?(Time)

  @checksum = Digest::MD5.digest(data)
end

Instance Attribute Details

#checksumObject (readonly)

Returns the value of attribute checksum.



7
8
9
# File 'lib/prawn/attachment/embedded_file.rb', line 7

def checksum
  @checksum
end

#creation_dateObject (readonly)

Returns the value of attribute creation_date.



7
8
9
# File 'lib/prawn/attachment/embedded_file.rb', line 7

def creation_date
  @creation_date
end

#dataObject (readonly)

Returns the value of attribute data.



7
8
9
# File 'lib/prawn/attachment/embedded_file.rb', line 7

def data
  @data
end

#modification_dateObject (readonly)

Returns the value of attribute modification_date.



7
8
9
# File 'lib/prawn/attachment/embedded_file.rb', line 7

def modification_date
  @modification_date
end

Instance Method Details

#build_pdf_object(document) ⇒ Object



21
22
23
24
25
26
# File 'lib/prawn/attachment/embedded_file.rb', line 21

def build_pdf_object(document)
  obj = document.ref!(reference_params)
  obj << data
  obj.stream.compress! if document.compression_enabled?
  obj
end