File: named.rb

package info (click to toggle)
origami-pdf 2.1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,484 kB
  • sloc: ruby: 17,883; makefile: 8
file content (33 lines) | stat: -rwxr-xr-x 668 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env ruby

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

OUTPUT_FILE = "#{File.basename(__FILE__, '.rb')}.pdf"

pdf = PDF.new

50.times do |n|
    pdf.append_page do |page|
        contents = ContentStream.new
        contents.write "page #{n+1}",
            x: 250, y: 450, rendering: Text::Rendering::FILL, size: 30

        page.Contents = contents

        if n != 49
            page.onOpen Action::Named::NEXT_PAGE
        else
            page.onOpen Action::Named::FIRST_PAGE
        end
    end
end

pdf.save(OUTPUT_FILE)

puts "PDF file saved as #{OUTPUT_FILE}."