Creates a new PDF document as a writing canvas. It accepts three named parameters:
| :paper: | Specifies the size of the default page in PDF::Writer. This may be a four-element array of coordinates specifying the lower-left (xll, yll) and upper-right (xur, yur) corners, a two-element array of width and height in centimetres, or a page name as defined in PAGE_SIZES. |
| :orientation: | The orientation of the page, either long (:portrait) or wide (:landscape). This may be used to swap the width and the height of the page. |
| :version: | The feature set available to the document is limited by the PDF version. Setting this version restricts the feature set available to PDF::Writer. PDF::Writer currently supports PDF version 1.3 features and does not yet support advanced features from PDF 1.4, 1.5, or 1.6. |
Source Code
# File pdf/writer.rb, line 325 def initialize(options = {}) paper = options[:paper] || "LETTER" orientation = options[:orientation] || :portrait version = options[:version] || PDF_VERSION_13 @mutex = Mutex.new @current_id = @current_font_id = 0 # Start the document @objects = [] @callbacks = [] @font_families = {} @fonts = {} @stack = [] @state_stack = StateStack.new @loose_objects = [] @current_text_state = "" @options = {} @destinations = {} @add_loose_objects = {} @images = [] @word_space_adjust = nil @current_stroke_style = PDF::Writer::StrokeStyle.new(1) @page_numbering = nil @arc4 = nil @encryption = nil @file_identifier = nil @columns = {} @columns_on = false @insert_mode = nil @catalog = PDF::Writer::Object::Catalog.new(self) @outlines = PDF::Writer::Object::Outlines.new(self) @pages = PDF::Writer::Object::Pages.new(self) @current_node = @pages @procset = PDF::Writer::Object::Procset.new(self) @info = PDF::Writer::Object::Info.new(self) @page = PDF::Writer::Object::Page.new(self) @current_text_render_style = 0 @first_page = @page @version = version # Initialize the default font families. init_font_families @font_size = 10 @pageset = [@pages.first_page] if paper.kind_of?(Array) if paper.size == 4 size = paper # Coordinate Array else size = [0, 0, PDF::Writer.cm2pts(paper[0]), PDF::Writer.cm2pts(paper[1])] # Paper size in centimeters has been passed end else size = PAGE_SIZES[paper.upcase].dup end size[3], size[2] = size[2], size[3] if orientation == :landscape @pages.media_box = size @page_width = size[2] - size[0] @page_height = size[3] - size[1] @y = @page_height # Also set the margins to some reasonable defaults -- 1.27 cm, 36pt, # or 0.5 inches. margins_pt(36) # Set the current writing position to the top of the first page @y = absolute_top_margin # Get the ID of the page that was created during the instantiation # process. fill_color! Color::RGB::Black stroke_color! Color::RGB::Black yield self if block_given? end
<code/>and<pre/>for code samples.