Created
March 26, 2009 13:09
-
-
Save yob/86079 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'prawn' | |
NAME_TREE_CHILDREN_LIMIT = 20 | |
Prawn::Document.generate "autoprint.pdf" do |pdf| | |
# Build the script we want to execute when the document opens | |
script = <<-EOF | |
var pp = this.getPrintParams(); | |
pp.interactive = pp.constants.interactionLevel.silent; | |
this.print(pp); | |
EOF | |
js_root = pdf.ref(Prawn::NameTree::Node.new(self, NAME_TREE_CHILDREN_LIMIT)) | |
pdf.names.data[:JavaScript] ||= js_root | |
# embed our script. The label is arbitary and can be anything | |
obj = pdf.ref(:S => :JavaScript, :JS => script) | |
# reference our JS fragment from the root javascript object | |
js_root.data.add("some_random_label_that_can_be_anything", obj) | |
# finally add some real content to the page so something gets printed. | |
pdf.text "Javascript Prototype", :at => [150,720], :size => 32 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment