File: page_margins.rb

package info (click to toggle)
ruby-prawn 2.2.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 4,320 kB
  • sloc: ruby: 15,654; sh: 43; makefile: 20
file content (34 lines) | stat: -rw-r--r-- 1,195 bytes parent folder | download
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
34
# The default margin for pages is 0.5 inch but you can change that with the
# <code>:margin</code> option or if you'd like to have different margins you
# can use the <code>:left_margin</code>, <code>:right_margin</code>,
# <code>:top_margin</code>, <code>:bottom_margin</code> options.
#
# These options are available both for starting new pages and creating new
# documents.

require_relative '../example_helper'

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::Document.generate(filename, margin: 100) do
  text '100 pts margins.'
  stroke_bounds

  start_new_page(left_margin: 300)
  text '300 pts margin on the left.'
  stroke_bounds

  start_new_page(top_margin: 300)
  text '300 pts margin both on the top and on the left. Notice that whenever ' \
    'you set an option for a new page it will remain the default for the ' \
    'following pages.'
  stroke_bounds

  start_new_page(margin: 50)
  text '50 pts margins. Using the margin option will reset previous specific ' \
    'calls to left, right, top and bottom margins.'
  stroke_bounds

  start_new_page(margin: [50, 100, 150, 200])
  text 'There is also the shorthand CSS like syntax used here.'
  stroke_bounds
end