File: single_usage.rb

package info (click to toggle)
ruby-prawn 2.4.0%2Bdfsg-1~
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 4,396 kB
  • sloc: ruby: 16,090; sh: 43; makefile: 20
file content (36 lines) | stat: -rw-r--r-- 1,234 bytes parent folder | download | duplicates (2)
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
35
36
# frozen_string_literal: true

# The PDF format has some built-in font support. If you want to use other fonts
# in Prawn you need to embed the font file.
#
# Doing this for a single font is extremely simple. Remember the Styling font
# example? Another use of the <code>font</code> method is to provide a font file
# path and the font will be embedded in the document and set as the current
# font.
#
# This is reasonable if a font is used only once, but, if a font used several
# times, providing the path each time it is used becomes cumbersome. The example
# on the next page shows a better way to deal with fonts which are used several
# times in a document.

require_relative '../example_helper'

filename = File.basename(__FILE__).gsub('.rb', '.pdf')
Prawn::ManualBuilder::Example.generate(filename) do
  # Using a TTF font file
  font("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf") do
    text 'Written with the DejaVu Sans TTF font.'
  end
  move_down 20

  text 'Written with the default font.'
  move_down 20

  # Using an DFONT font file
  font("#{Prawn::DATADIR}/fonts/Panic+Sans.dfont") do
    text 'Written with the Panic Sans DFONT font'
  end
  move_down 20

  text 'Written with the default font once more.'
end