#!/usr/bin/ruby 
# -*- coding: iso-8859-1 -*-


$: << "../../../../../sources/parser"

require 'parser.rb'

include Origami

OUTPUTFILE = "webpong.pdf"
OTHERFILE = "webping.pdf"

puts "Now generating a new PDF file from scratch!"

##################
# Création à la volée d'un PDF #
##################

# Création de l'objet PDF
pdf = PDF.new

contents = ContentStream.new
contents.write OUTPUTFILE,
  :x => 350, :y => 750, :rendering => PS::Text::Rendering::STROKE, :size => 30

contents.write "Empty test file",
  :x => 186, :y => 690, :rendering => PS::Text::Rendering::FILL, :size => 15

page = Page.new
page.Contents = contents
pdf.append_page(page)

######
# PLAYGROUND
######
js = Action::JavaScript.new("app.alert(\"You are in #{OUTPUTFILE}\")")
page.onOpen(js)


dst = ExternalFile.new(OTHERFILE)
gotor = Action::GoToR.new(dst, Destination::GlobalFit.new(0)).set_indirect(true)
js.Next = gotor

# Sauvegarde du fichier
pdf.saveas(OUTPUTFILE)

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


