#!/usr/bin/ruby require 'pdfwriter.rb' pdf = PdfWriter.new($stdout, 'Test', :mm) # Write to stdout, pdf title, units # Alternative units :points and :inches pdf.newPage pdf.writeText(10, 200, 'Simple text, big font', :fontsize => 18, :bold => true) pdf.writeLine(0, 0, 200, 200) pdf.newPage pdf.writeTxtBox(200, 10, 100, 'Or for a better way of writing text use writeTextBox which takes 4 mandatory arguments - the y coordinate to start writing at, the left edge of the writable area, and the right hand edge of the writable area plus the text. Anything that would pass the right hand edge is wrapped onto the next line.') pdf.writeLine(100, 210, 100, 130) pdf.writeTxtBox(120, 10, 200, 'Finally writeTxtLine() takes a y axis argument and an array of words to write along that line at various positions') # Word x-pos right-justify? (optional) line = [ [ 'This', 32, false ], [ 'can be', 60, false ], [ 'used for', 90, true ], [ 'column headings', 140] ] pdf.writeTxtLine(100, line) pdf.endPage # The other method of doing things is to define various streams with # startStream and endStream. Between these we can write as usual, but save the # value returned by one or other of them. writePage takes a variable number # of streams as arguments, and will write them all onto a new page. Each # stream can be used as often or little as required. writePage must be called # after a stream has ended titlePage = pdf.startStream pdf.writeText(10, 210, 'Title for Every Page') #As much other drawing as you want here pdf.endStream pdf.startStream pdf.writeText(10, 10, 'Every page gets a footer as well', :bold => true) footerPage = pdf.endStream #endStream or startStream both return the stream 3.times do |i| pdf.startStream pdf.writeText(10, 100, "Page number #{i}", :fontsize => 28) thisPage = pdf.endStream pdf.writePage(thisPage, titlePage, footerPage) end #We must finish with a writeEnd command to finalise the file. If using newPage #Then you don't need to do an endPage before this - it is automatically closed. #If using streams they must be closed. pdf.writeEnd