Sha256: 77c76e8375803c6f77f2e4e22d67895854f8443a1c8b870ad025087f1900330b

Contents?: true

Size: 1.09 KB

Versions: 7

Compression:

Stored size: 1.09 KB

Contents

#!/usr/bin/env ruby

begin
    require 'origami'
rescue LoadError
    $: << File.join(__dir__, '../../lib')
    require 'origami'
end
include Origami

require 'stringio'

OUTPUT_FILE = "#{File.basename(__FILE__, ".rb")}.pdf"
EMBEDDED_NAME = "#{('a'..'z').to_a.sample(8).join}.pdf"

#
# Creates the nested document.
# A simple document displaying a message box.
#
output_str = StringIO.new
PDF.write(output_str) do |pdf|
    pdf.onDocumentOpen Action::JavaScript "app.alert('Hello world!');" 
end

output_str.rewind

# The envelope document.
pdf = PDF.new.append_page

# Create an object stream to compress objects.
objstm = ObjectStream.new
objstm.Filter = :FlateDecode

pdf.insert(objstm)

objstm.insert pdf.attach_file(output_str, register: true, name: EMBEDDED_NAME)

# Compress the page tree.
objstm.insert(pdf.Catalog.Pages)
objstm.insert(pdf.pages.first)

# Compress the name tree.
objstm.insert(pdf.Catalog.Names)
objstm.insert(pdf.Catalog.Names.EmbeddedFiles)

# Compress the catalog.
objstm.insert(pdf.Catalog)

pdf.pages.first.onOpen Action::GoToE[EMBEDDED_NAME]

pdf.save(OUTPUT_FILE, noindent: true)

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
origamindee-3.1.0 examples/attachments/nested_document.rb
origamindee-3.0.0 examples/attachments/nested_document.rb
origami-2.1.0 examples/attachments/nested_document.rb
origami-2.0.4 examples/attachments/nested_document.rb
origami-2.0.3 examples/attachments/nested_document.rb
origami-2.0.2 examples/attachments/nested_document.rb
origami-2.0.1 examples/attachments/nested_document.rb