prawn 2.3.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/lib/prawn/document/bounding_box.rb +223 -143
  4. data/lib/prawn/document/column_box.rb +61 -26
  5. data/lib/prawn/document/internals.rb +25 -16
  6. data/lib/prawn/document/span.rb +21 -18
  7. data/lib/prawn/document.rb +273 -182
  8. data/lib/prawn/encoding.rb +2 -5
  9. data/lib/prawn/errors.rb +23 -34
  10. data/lib/prawn/font.rb +254 -139
  11. data/lib/prawn/font_metric_cache.rb +18 -16
  12. data/lib/prawn/fonts/afm.rb +99 -57
  13. data/lib/prawn/fonts/dfont.rb +7 -1
  14. data/lib/prawn/fonts/otf.rb +4 -1
  15. data/lib/prawn/fonts/to_unicode_cmap.rb +151 -0
  16. data/lib/prawn/fonts/ttc.rb +7 -2
  17. data/lib/prawn/fonts/ttf.rb +345 -107
  18. data/lib/prawn/fonts.rb +14 -0
  19. data/lib/prawn/graphics/blend_mode.rb +25 -28
  20. data/lib/prawn/graphics/cap_style.rb +9 -12
  21. data/lib/prawn/graphics/color.rb +75 -50
  22. data/lib/prawn/graphics/dash.rb +45 -42
  23. data/lib/prawn/graphics/join_style.rb +18 -12
  24. data/lib/prawn/graphics/patterns.rb +239 -110
  25. data/lib/prawn/graphics/transformation.rb +51 -44
  26. data/lib/prawn/graphics/transparency.rb +16 -40
  27. data/lib/prawn/graphics.rb +370 -260
  28. data/lib/prawn/grid.rb +219 -57
  29. data/lib/prawn/image_handler.rb +27 -10
  30. data/lib/prawn/images/image.rb +8 -10
  31. data/lib/prawn/images/jpg.rb +46 -20
  32. data/lib/prawn/images/png.rb +94 -42
  33. data/lib/prawn/images.rb +70 -81
  34. data/lib/prawn/measurement_extensions.rb +39 -8
  35. data/lib/prawn/measurements.rb +60 -5
  36. data/lib/prawn/outline.rb +120 -113
  37. data/lib/prawn/repeater.rb +52 -36
  38. data/lib/prawn/security/arcfour.rb +4 -4
  39. data/lib/prawn/security.rb +106 -98
  40. data/lib/prawn/soft_mask.rb +42 -30
  41. data/lib/prawn/stamp.rb +38 -42
  42. data/lib/prawn/text/box.rb +156 -105
  43. data/lib/prawn/text/formatted/arranger.rb +121 -41
  44. data/lib/prawn/text/formatted/box.rb +239 -163
  45. data/lib/prawn/text/formatted/fragment.rb +130 -14
  46. data/lib/prawn/text/formatted/line_wrap.rb +49 -38
  47. data/lib/prawn/text/formatted/parser.rb +116 -74
  48. data/lib/prawn/text/formatted/wrap.rb +25 -26
  49. data/lib/prawn/text/formatted.rb +75 -0
  50. data/lib/prawn/text.rb +456 -211
  51. data/lib/prawn/transformation_stack.rb +29 -10
  52. data/lib/prawn/utilities.rb +13 -13
  53. data/lib/prawn/version.rb +2 -1
  54. data/lib/prawn/view.rb +69 -54
  55. data/lib/prawn.rb +24 -18
  56. data.tar.gz.sig +0 -0
  57. metadata +55 -262
  58. metadata.gz.sig +3 -4
  59. data/.yardopts +0 -10
  60. data/Gemfile +0 -5
  61. data/Rakefile +0 -54
  62. data/manual/absolute_position.pdf +0 -0
  63. data/manual/basic_concepts/adding_pages.rb +0 -26
  64. data/manual/basic_concepts/basic_concepts.rb +0 -43
  65. data/manual/basic_concepts/creation.rb +0 -38
  66. data/manual/basic_concepts/cursor.rb +0 -32
  67. data/manual/basic_concepts/measurement.rb +0 -24
  68. data/manual/basic_concepts/origin.rb +0 -37
  69. data/manual/basic_concepts/other_cursor_helpers.rb +0 -39
  70. data/manual/basic_concepts/view.rb +0 -48
  71. data/manual/bounding_box/bounding_box.rb +0 -41
  72. data/manual/bounding_box/bounds.rb +0 -48
  73. data/manual/bounding_box/canvas.rb +0 -23
  74. data/manual/bounding_box/creation.rb +0 -22
  75. data/manual/bounding_box/indentation.rb +0 -45
  76. data/manual/bounding_box/nesting.rb +0 -52
  77. data/manual/bounding_box/russian_boxes.rb +0 -40
  78. data/manual/bounding_box/stretchy.rb +0 -29
  79. data/manual/contents.rb +0 -35
  80. data/manual/cover.rb +0 -43
  81. data/manual/document_and_page_options/background.rb +0 -25
  82. data/manual/document_and_page_options/document_and_page_options.rb +0 -34
  83. data/manual/document_and_page_options/metadata.rb +0 -25
  84. data/manual/document_and_page_options/page_margins.rb +0 -36
  85. data/manual/document_and_page_options/page_size.rb +0 -34
  86. data/manual/document_and_page_options/print_scaling.rb +0 -22
  87. data/manual/example_helper.rb +0 -8
  88. data/manual/graphics/blend_mode.rb +0 -52
  89. data/manual/graphics/circle_and_ellipse.rb +0 -21
  90. data/manual/graphics/color.rb +0 -22
  91. data/manual/graphics/common_lines.rb +0 -29
  92. data/manual/graphics/fill_and_stroke.rb +0 -41
  93. data/manual/graphics/fill_rules.rb +0 -37
  94. data/manual/graphics/gradients.rb +0 -43
  95. data/manual/graphics/graphics.rb +0 -64
  96. data/manual/graphics/helper.rb +0 -27
  97. data/manual/graphics/line_width.rb +0 -36
  98. data/manual/graphics/lines_and_curves.rb +0 -40
  99. data/manual/graphics/polygon.rb +0 -27
  100. data/manual/graphics/rectangle.rb +0 -20
  101. data/manual/graphics/rotate.rb +0 -25
  102. data/manual/graphics/scale.rb +0 -42
  103. data/manual/graphics/soft_masks.rb +0 -44
  104. data/manual/graphics/stroke_cap.rb +0 -30
  105. data/manual/graphics/stroke_dash.rb +0 -47
  106. data/manual/graphics/stroke_join.rb +0 -29
  107. data/manual/graphics/translate.rb +0 -28
  108. data/manual/graphics/transparency.rb +0 -33
  109. data/manual/how_to_read_this_manual.rb +0 -39
  110. data/manual/images/absolute_position.rb +0 -22
  111. data/manual/images/fit.rb +0 -20
  112. data/manual/images/horizontal.rb +0 -24
  113. data/manual/images/images.rb +0 -41
  114. data/manual/images/plain_image.rb +0 -17
  115. data/manual/images/scale.rb +0 -21
  116. data/manual/images/vertical.rb +0 -27
  117. data/manual/images/width_and_height.rb +0 -24
  118. data/manual/layout/boxes.rb +0 -26
  119. data/manual/layout/content.rb +0 -24
  120. data/manual/layout/layout.rb +0 -27
  121. data/manual/layout/simple_grid.rb +0 -22
  122. data/manual/outline/add_subsection_to.rb +0 -60
  123. data/manual/outline/insert_section_after.rb +0 -46
  124. data/manual/outline/outline.rb +0 -33
  125. data/manual/outline/sections_and_pages.rb +0 -66
  126. data/manual/repeatable_content/alternate_page_numbering.rb +0 -36
  127. data/manual/repeatable_content/page_numbering.rb +0 -55
  128. data/manual/repeatable_content/repeatable_content.rb +0 -35
  129. data/manual/repeatable_content/repeater.rb +0 -54
  130. data/manual/repeatable_content/stamp.rb +0 -40
  131. data/manual/security/encryption.rb +0 -28
  132. data/manual/security/permissions.rb +0 -41
  133. data/manual/security/security.rb +0 -28
  134. data/manual/table.rb +0 -16
  135. data/manual/text/alignment.rb +0 -43
  136. data/manual/text/color.rb +0 -24
  137. data/manual/text/column_box.rb +0 -30
  138. data/manual/text/fallback_fonts.rb +0 -41
  139. data/manual/text/font.rb +0 -40
  140. data/manual/text/font_size.rb +0 -44
  141. data/manual/text/font_style.rb +0 -22
  142. data/manual/text/formatted_callbacks.rb +0 -65
  143. data/manual/text/formatted_text.rb +0 -58
  144. data/manual/text/free_flowing_text.rb +0 -50
  145. data/manual/text/inline.rb +0 -40
  146. data/manual/text/kerning_and_character_spacing.rb +0 -38
  147. data/manual/text/leading.rb +0 -24
  148. data/manual/text/line_wrapping.rb +0 -60
  149. data/manual/text/paragraph_indentation.rb +0 -32
  150. data/manual/text/positioned_text.rb +0 -37
  151. data/manual/text/registering_families.rb +0 -51
  152. data/manual/text/rendering_and_color.rb +0 -36
  153. data/manual/text/right_to_left_text.rb +0 -54
  154. data/manual/text/rotation.rb +0 -47
  155. data/manual/text/single_usage.rb +0 -36
  156. data/manual/text/text.rb +0 -75
  157. data/manual/text/text_box_excess.rb +0 -35
  158. data/manual/text/text_box_extensions.rb +0 -48
  159. data/manual/text/text_box_overflow.rb +0 -49
  160. data/manual/text/utf8.rb +0 -27
  161. data/manual/text/win_ansi_charset.rb +0 -62
  162. data/prawn.gemspec +0 -57
  163. data/spec/data/curves.pdf +0 -66
  164. data/spec/extensions/encoding_helpers.rb +0 -11
  165. data/spec/prawn/document/bounding_box_spec.rb +0 -546
  166. data/spec/prawn/document/column_box_spec.rb +0 -75
  167. data/spec/prawn/document/security_spec.rb +0 -176
  168. data/spec/prawn/document_annotations_spec.rb +0 -76
  169. data/spec/prawn/document_destinations_spec.rb +0 -15
  170. data/spec/prawn/document_grid_spec.rb +0 -99
  171. data/spec/prawn/document_reference_spec.rb +0 -27
  172. data/spec/prawn/document_span_spec.rb +0 -36
  173. data/spec/prawn/document_spec.rb +0 -802
  174. data/spec/prawn/font_metric_cache_spec.rb +0 -54
  175. data/spec/prawn/font_spec.rb +0 -542
  176. data/spec/prawn/graphics/blend_mode_spec.rb +0 -63
  177. data/spec/prawn/graphics/transparency_spec.rb +0 -81
  178. data/spec/prawn/graphics_spec.rb +0 -837
  179. data/spec/prawn/graphics_stroke_styles_spec.rb +0 -229
  180. data/spec/prawn/image_handler_spec.rb +0 -53
  181. data/spec/prawn/images/jpg_spec.rb +0 -20
  182. data/spec/prawn/images/png_spec.rb +0 -283
  183. data/spec/prawn/images_spec.rb +0 -224
  184. data/spec/prawn/measurements_extensions_spec.rb +0 -24
  185. data/spec/prawn/outline_spec.rb +0 -412
  186. data/spec/prawn/repeater_spec.rb +0 -165
  187. data/spec/prawn/soft_mask_spec.rb +0 -74
  188. data/spec/prawn/stamp_spec.rb +0 -172
  189. data/spec/prawn/text/box_spec.rb +0 -1112
  190. data/spec/prawn/text/formatted/arranger_spec.rb +0 -466
  191. data/spec/prawn/text/formatted/box_spec.rb +0 -846
  192. data/spec/prawn/text/formatted/fragment_spec.rb +0 -343
  193. data/spec/prawn/text/formatted/line_wrap_spec.rb +0 -494
  194. data/spec/prawn/text/formatted/parser_spec.rb +0 -697
  195. data/spec/prawn/text_draw_text_spec.rb +0 -149
  196. data/spec/prawn/text_rendering_mode_spec.rb +0 -48
  197. data/spec/prawn/text_spacing_spec.rb +0 -95
  198. data/spec/prawn/text_spec.rb +0 -603
  199. data/spec/prawn/text_with_inline_formatting_spec.rb +0 -35
  200. data/spec/prawn/transformation_stack_spec.rb +0 -66
  201. data/spec/prawn/view_spec.rb +0 -63
  202. data/spec/prawn_manual_spec.rb +0 -35
  203. data/spec/spec_helper.rb +0 -48
@@ -1,66 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The document outline tree is the set of links used to navigate through the
4
- # various document sections and pages.
5
- #
6
- # To define the document outline we first use the <code>outline</code>
7
- # method to lazily instantiate an outline object. Then we use the
8
- # <code>define</code> method with a block to start the outline tree.
9
- #
10
- # The basic methods for creating outline nodes are <code>section</code> and
11
- # <code>page</code>. The only difference between the two is that
12
- # <code>page</code> doesn't accept a block and will only create leaf nodes
13
- # while <code>section</code> accepts a block to create nested nodes.
14
- #
15
- # <code>section</code> accepts the title of the section and two options:
16
- # <code>:destination</code> - a page number to link and <code>:closed</code> -
17
- # a boolean value that defines if the nested outline nodes are shown when the
18
- # document is open (defaults to true).
19
- #
20
- # <code>page</code> is very similar to section. It requires a
21
- # <code>:title</code> option to be set and accepts a <code>:destination</code>.
22
- #
23
- # <code>section</code> and <code>page</code> may also be used without the
24
- # <code>define</code> method but they will need to instantiate the
25
- # <code>outline</code> object every time.
26
-
27
- require_relative '../example_helper'
28
-
29
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
30
- Prawn::ManualBuilder::Example.generate(filename) do
31
- # First we create 10 pages just to have something to link to
32
- (1..10).each do |index|
33
- text "Page #{index}"
34
- start_new_page
35
- end
36
-
37
- outline.define do
38
- section('Section 1', destination: 1) do
39
- page title: 'Page 2', destination: 2
40
- page title: 'Page 3', destination: 3
41
- end
42
-
43
- section('Section 2', destination: 4) do
44
- page title: 'Page 5', destination: 5
45
-
46
- section('Subsection 2.1', destination: 6, closed: true) do
47
- page title: 'Page 7', destination: 7
48
- end
49
- end
50
- end
51
-
52
- # Outside of the define block
53
- outline.section('Section 3', destination: 8) do
54
- outline.page title: 'Page 9', destination: 9
55
- end
56
-
57
- outline.page title: 'Page 10', destination: 10
58
-
59
- # Section and Pages without links. While a section without a link may be
60
- # useful to group some pages, a page without a link is useless
61
- outline.update do # update is an alias to define
62
- section('Section without link') do
63
- page title: 'Page without link'
64
- end
65
- end
66
- end
@@ -1,36 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Below is the code to generate page numbers that alternate being rendered
4
- # on the right and left side of the page. The first page will have a "1" in
5
- # the bottom right corner. The second page will have a "2" in the bottom
6
- # left corner of the page. The third a "3" in the bottom right, etc.
7
-
8
- require_relative '../example_helper'
9
-
10
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
11
- Prawn::ManualBuilder::Example.generate(filename) do
12
- text 'This is the first page!'
13
-
14
- 10.times do
15
- start_new_page
16
- text 'Here comes yet another page.'
17
- end
18
-
19
- string = '<page>'
20
- odd_options = {
21
- at: [bounds.right - 150, 0],
22
- width: 150,
23
- align: :right,
24
- page_filter: :odd,
25
- start_count_at: 1
26
- }
27
- even_options = {
28
- at: [0, bounds.left],
29
- width: 150,
30
- align: :left,
31
- page_filter: :even,
32
- start_count_at: 2
33
- }
34
- number_pages string, odd_options
35
- number_pages string, even_options
36
- end
@@ -1,55 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The <code>number_pages</code> method is a simple way to number the pages of
4
- # your document. It should be called towards the end of the document since
5
- # pages created after the call won't be numbered.
6
- #
7
- # It accepts a string and a hash of options:
8
- #
9
- # <code>start_count_at</code> is the value from which to start numbering pages
10
- #
11
- # <code>total_pages</code> If provided, will replace <code>total</code> with
12
- # the value given. Useful for overriding the total number of pages when using
13
- # the start_count_at option.
14
- #
15
- # <code>page_filter</code>, which is one of: <code>:all</code>,
16
- # <code>:odd</code>, <code>:even</code>, an array, a range, or a Proc that
17
- # receives the page number as an argument and should return true if the page
18
- # number should be printed on that page.
19
- #
20
- # <code>color</code> which accepts the same values as <code>fill_color</code>
21
- #
22
- # As well as any option accepted by <code>text_box</code>
23
-
24
- require_relative '../example_helper'
25
-
26
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
27
- Prawn::ManualBuilder::Example.generate(filename) do
28
- text 'This is the first page!'
29
-
30
- 10.times do
31
- start_new_page
32
- text 'Here comes yet another page.'
33
- end
34
-
35
- string = 'page <page> of <total>'
36
- # Green page numbers 1 to 7
37
- options = {
38
- at: [bounds.right - 150, 0],
39
- width: 150,
40
- align: :right,
41
- page_filter: (1..7),
42
- start_count_at: 1,
43
- color: '007700'
44
- }
45
- number_pages string, options
46
-
47
- # Gray page numbers from 8 on up
48
- options[:page_filter] = ->(pg) { pg > 7 }
49
- options[:start_count_at] = 8
50
- options[:color] = '333333'
51
- number_pages string, options
52
-
53
- start_new_page
54
- text "See. This page isn't numbered and doesn't count towards the total."
55
- end
@@ -1,35 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Examples for stamps and repeaters.
4
-
5
- require_relative '../example_helper'
6
-
7
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
8
- Prawn::ManualBuilder::Example.generate(filename, page_size: 'FOLIO') do
9
- package 'repeatable_content' do |p|
10
- p.example 'repeater', eval_source: false
11
- p.example 'stamp'
12
- p.example 'page_numbering', eval_source: false
13
- p.example 'alternate_page_numbering', eval_source: false
14
-
15
- p.intro do
16
- prose <<-TEXT
17
- Prawn offers two ways to handle repeatable content blocks. Repeater is
18
- useful for content that gets repeated at well defined intervals while
19
- Stamp is more appropriate if you need better control of when to repeat
20
- it.
21
-
22
- There is also one very specific helper for numbering pages.
23
-
24
- The examples show:
25
- TEXT
26
-
27
- list(
28
- 'How to repeat content on several pages with a single invocation',
29
- 'How to create a new Stamp',
30
- 'How to "stamp" the content block on the page',
31
- 'How to number the document pages with one simple call'
32
- )
33
- end
34
- end
35
- end
@@ -1,54 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The <code>repeat</code> method is quite versatile when it comes to define
4
- # the intervals at which the content block should repeat.
5
- #
6
- # The interval may be a symbol (<code>:all</code>, <code>:odd</code>,
7
- # <code>:even</code>), an array listing the pages, a range or a
8
- # <code>Proc</code> that receives the page number as an argument and should
9
- # return true if the content is to be repeated on the given page.
10
- #
11
- # You may also pass an option <code>:dynamic</code> to reevaluate the code block
12
- # on every call which is useful when the content changes based on the page
13
- # number.
14
- #
15
- # It is also important to say that no matter where you define the repeater it
16
- # will be applied to all matching pages.
17
-
18
- require_relative '../example_helper'
19
-
20
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
21
- Prawn::ManualBuilder::Example.generate(filename) do
22
- repeat(:all) do
23
- draw_text 'All pages', at: bounds.top_left
24
- end
25
-
26
- repeat(:odd) do
27
- draw_text 'Only odd pages', at: [0, 0]
28
- end
29
-
30
- repeat(:even) do
31
- draw_text 'Only even pages', at: [0, 0]
32
- end
33
-
34
- repeat([1, 3, 7]) do
35
- draw_text 'Only on pages 1, 3 and 7', at: [100, 0]
36
- end
37
-
38
- repeat(2..4) do
39
- draw_text 'From the 2nd to the 4th page', at: [300, 0]
40
- end
41
-
42
- repeat(->(pg) { (pg % 3).zero? }) do
43
- draw_text 'Every third page', at: [250, 20]
44
- end
45
-
46
- repeat(:all, dynamic: true) do
47
- draw_text page_number, at: [500, 0]
48
- end
49
-
50
- 10.times do
51
- start_new_page
52
- draw_text 'A wonderful page', at: [400, 400]
53
- end
54
- end
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Stamps should be used when you have content that will be included multiple
4
- # times in a document. Its advantages over creating the content anew each time
5
- # are:
6
- # 1. Faster document creation
7
- # 2. Smaller final document
8
- # 3. Faster display on subsequent displays of the repeated
9
- # element because the viewer application can cache the rendered
10
- # results
11
- #
12
- # The <code>create_stamp</code> method does just what it says. Pass it a block
13
- # with the content that should be generated and the stamp will be created.
14
- #
15
- # There are two methods to render the stamp on a page <code>stamp</code> and
16
- # <code>stamp_at</code>. The first will render the stamp as is while the
17
- # second accepts a point to serve as an offset to the stamp content.
18
-
19
- require_relative '../example_helper'
20
-
21
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
22
- Prawn::ManualBuilder::Example.generate(filename) do
23
- create_stamp('approved') do
24
- rotate(30, origin: [-5, -5]) do
25
- stroke_color 'FF3333'
26
- stroke_ellipse [0, 0], 29, 15
27
- stroke_color '000000'
28
-
29
- fill_color '993333'
30
- font('Times-Roman') do
31
- draw_text 'Approved', at: [-23, -3]
32
- end
33
- fill_color '000000'
34
- end
35
- end
36
-
37
- stamp 'approved'
38
-
39
- stamp_at 'approved', [200, 200]
40
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The <code>encrypt_document</code> method, as you might have already guessed,
4
- # is used to encrypt the PDF document.
5
- #
6
- # Once encrypted whoever is using the document will need the user password to
7
- # read the document. This password can be set with the
8
- # <code>:user_password</code> option. If this is not set the document will be
9
- # encrypted but a password will not be needed to read the document.
10
- #
11
- # There are some caveats when encrypting your PDFs. Be sure to read the source
12
- # documentation (you can find it here:
13
- # https://github.com/prawnpdf/prawn/blob/master/lib/prawn/security.rb ) before
14
- # using this for anything super serious.
15
-
16
- require_relative '../example_helper'
17
-
18
- # Bare encryption. No password needed.
19
- Prawn::ManualBuilder::Example.generate('bare_encryption.pdf') do
20
- text 'See, no password was asked but the document is still encrypted.'
21
- encrypt_document
22
- end
23
-
24
- # Simple password. All permissions granted.
25
- Prawn::ManualBuilder::Example.generate('simple_password.pdf') do
26
- text 'You was asked for a password.'
27
- encrypt_document(user_password: 'foo', owner_password: 'bar')
28
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Some permissions may be set for the regular user with the following options:
4
- # <code>:print_document</code>, <code>:modify_contents</code>,
5
- # <code>:copy_contents</code>, <code>:modify_annotations</code>. All this
6
- # options default to true, so if you'd like to revoke just set them to false.
7
- #
8
- # A user may bypass all permissions if he provides the owner password which
9
- # may be set with the <code>:owner_password</code> option. This option may be
10
- # set to <code>:random</code> so that users will never be able to bypass
11
- # permissions.
12
- #
13
- # There are some caveats when encrypting your PDFs. Be sure to read the source
14
- # documentation (you can find it here:
15
- # https://github.com/prawnpdf/prawn/blob/master/lib/prawn/security.rb ) before
16
- # using this for anything super serious.
17
-
18
- require_relative '../example_helper'
19
-
20
- # User cannot print the document.
21
- Prawn::ManualBuilder::Example.generate('cannot_print.pdf') do
22
- text "If you used the user password you won't be able to print the doc."
23
- encrypt_document(
24
- user_password: 'foo', owner_password: 'bar',
25
- permissions: { print_document: false }
26
- )
27
- end
28
-
29
- # All permissions revoked and owner password set to random
30
- Prawn::ManualBuilder::Example.generate('no_permissions.pdf') do
31
- text "You may only view this and won't be able to use the owner password."
32
- encrypt_document(
33
- user_password: 'foo', owner_password: :random,
34
- permissions: {
35
- print_document: false,
36
- modify_contents: false,
37
- copy_contents: false,
38
- modify_annotations: false
39
- }
40
- )
41
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Examples for document encryption.
4
-
5
- require_relative '../example_helper'
6
-
7
- Prawn::ManualBuilder::Example.generate('security.pdf', page_size: 'FOLIO') do
8
- package 'security' do |p|
9
- p.example 'encryption', eval_source: false, full_source: true
10
- p.example 'permissions', eval_source: false, full_source: true
11
-
12
- p.intro do
13
- prose <<-TEXT
14
- Security lets you control who can read the document by defining
15
- a password.
16
-
17
- The examples include:
18
- TEXT
19
-
20
- list(
21
- 'How to encrypt the document without the need for a password',
22
- 'How to configure the regular user permissions',
23
- 'How to require a password for the regular user',
24
- 'How to set a owner password that bypass the document permissions'
25
- )
26
- end
27
- end
28
- end
data/manual/table.rb DELETED
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'example_helper'
4
-
5
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
6
-
7
- Prawn::ManualBuilder::Example.generate(filename) do
8
- header('Prawn::Table')
9
-
10
- prose <<-END_TEXT
11
- As of Prawn 1.2.0, Prawn::Table has been extracted into its own
12
- semi-officially supported gem.
13
-
14
- Please see https://github.com/prawnpdf/prawn-table for more details.
15
- END_TEXT
16
- end
@@ -1,43 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Horizontal text alignment can be achieved by supplying the <code>:align</code>
4
- # option to the text methods. Available options are <code>:left</code>
5
- # (default), <code>:right</code>, <code>:center</code>, and
6
- # <code>:justify</code>.
7
- #
8
- # Vertical text alignment can be achieved using the <code>:valign</code> option
9
- # with the text methods. Available options are <code>:top</code> (default),
10
- # <code>:center</code>, and <code>:bottom</code>.
11
- #
12
- # Both forms of alignment will be evaluated in the context of the current
13
- # bounding_box.
14
-
15
- require_relative '../example_helper'
16
-
17
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
18
- Prawn::ManualBuilder::Example.generate(filename) do
19
- text 'This text should be left aligned'
20
- text 'This text should be centered', align: :center
21
- text 'This text should be right aligned', align: :right
22
-
23
- bounding_box([0, 220], width: 250, height: 220) do
24
- text 'This text is flowing from the left. ' * 4
25
-
26
- move_down 15
27
- text 'This text is flowing from the center. ' * 3, align: :center
28
-
29
- move_down 15
30
- text 'This text is flowing from the right. ' * 4, align: :right
31
-
32
- move_down 15
33
- text 'This text is justified. ' * 6, align: :justify
34
- transparent(0.5) { stroke_bounds }
35
- end
36
-
37
- bounding_box([300, 220], width: 250, height: 220) do
38
- text 'This text should be vertically top aligned'
39
- text 'This text should be vertically centered', valign: :center
40
- text 'This text should be vertically bottom aligned', valign: :bottom
41
- transparent(0.5) { stroke_bounds }
42
- end
43
- end
data/manual/text/color.rb DELETED
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The <code>:color</code> attribute can give a block of text a default color,
4
- # in RGB hex format or 4-value CMYK.
5
-
6
- require_relative '../example_helper'
7
-
8
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
9
- Prawn::ManualBuilder::Example.generate(filename) do
10
- text 'Default color is black'
11
- move_down 25
12
-
13
- text 'Changed to red', color: 'FF0000'
14
- move_down 25
15
-
16
- text 'CMYK color', color: [22, 55, 79, 30]
17
- move_down 25
18
-
19
- text(
20
- "Also works with <color rgb='ff0000'>inline</color> formatting",
21
- color: '0000FF',
22
- inline_format: true
23
- )
24
- end
@@ -1,30 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The <code>column_box</code> method allows you to define columns that flow
4
- # their contents from one section to the next. You can have a number of columns
5
- # on the page, and only when the last column overflows will a new page be
6
- # created.
7
-
8
- require_relative '../example_helper'
9
-
10
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
11
- Prawn::ManualBuilder::Example.generate(filename) do
12
- text 'The Prince', align: :center, size: 18
13
- text 'Niccolò Machiavelli', align: :center, size: 14
14
- move_down 12
15
-
16
- column_box([0, cursor], columns: 2, width: bounds.width) do
17
- text((<<-TEXT.gsub(/\s+/, ' ') + "\n\n") * 3)
18
- All the States and Governments by which men are or ever have been ruled,
19
- have been and are either Republics or Princedoms. Princedoms are either
20
- hereditary, in which the sovereignty is derived through an ancient line
21
- of ancestors, or they are new. New Princedoms are either wholly new, as
22
- that of Milan to Francesco Sforza; or they are like limbs joined on to
23
- the hereditary possessions of the Prince who acquires them, as the
24
- Kingdom of Naples to the dominions of the King of Spain. The States thus
25
- acquired have either been used to live under a Prince or have been free;
26
- and he who acquires them does so either by his own arms or by the arms of
27
- others, and either by good fortune or by merit.
28
- TEXT
29
- end
30
- end
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Prawn enables the declaration of fallback fonts for those glyphs that may not
4
- # be present in the desired font. Use the <code>:fallback_fonts</code> option
5
- # with any of the text or text box methods, or set fallback_fonts document-wide.
6
-
7
- require_relative '../example_helper'
8
-
9
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
10
- Prawn::ManualBuilder::Example.generate(filename) do
11
- file = "#{Prawn::DATADIR}/fonts/gkai00mp.ttf"
12
- font_families['Kai'] = {
13
- normal: { file: file, font: 'Kai' }
14
- }
15
-
16
- file = "#{Prawn::DATADIR}/fonts/Panic+Sans.dfont"
17
- font_families['Panic Sans'] = {
18
- normal: { file: file, font: 'PanicSans' }
19
- }
20
-
21
- font('Panic Sans') do
22
- text(
23
- 'When fallback fonts are included, each glyph will be rendered ' \
24
- 'using the first font that includes the glyph, starting with the ' \
25
- 'current font and then moving through the fallback fonts from left ' \
26
- 'to right.' \
27
- "\n\n" \
28
- "hello ƒ 你好\n再见 ƒ goodbye",
29
- fallback_fonts: %w[Times-Roman Kai]
30
- )
31
- end
32
- move_down 20
33
-
34
- formatted_text(
35
- [
36
- { text: 'Fallback fonts can even override' },
37
- { text: 'fragment fonts (你好)', font: 'Times-Roman' }
38
- ],
39
- fallback_fonts: %w[Times-Roman Kai]
40
- )
41
- end
data/manual/text/font.rb DELETED
@@ -1,40 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The <code>font</code> method can be used in three different ways.
4
- #
5
- # If we don't pass it any arguments it will return the current font being used
6
- # to render text.
7
- #
8
- # If we just pass it a font name it will use that font for rendering text
9
- # through the rest of the document.
10
- #
11
- # It can also be used by passing a font name and a block. In this case the
12
- # specified font will only be used to render text inside the block.
13
- #
14
- # The default font is Helvetica.
15
-
16
- require_relative '../example_helper'
17
-
18
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
19
- Prawn::ManualBuilder::Example.generate(filename) do
20
- text "Let's see which font we are using: #{font.inspect}"
21
-
22
- move_down 20
23
- font 'Times-Roman'
24
- text 'Written in Times.'
25
-
26
- move_down 20
27
- font('Courier') do
28
- text 'Written in Courier because we are inside the block.'
29
- end
30
-
31
- move_down 20
32
- text 'Written in Times again as we left the previous block.'
33
-
34
- move_down 20
35
- text "Let's see which font we are using again: #{font.inspect}"
36
-
37
- move_down 20
38
- font 'Helvetica'
39
- text 'Back to normal.'
40
- end
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # The <code>font_size</code> method works just like the <code>font</code>
4
- # method.
5
- #
6
- # In fact we can even use <code>font</code> with the <code>:size</code> option
7
- # to declare which size we want.
8
- #
9
- # Another way to change the font size is by supplying the <code>:size</code>
10
- # option to the text methods.
11
- #
12
- # The default font size is <code>12</code>.
13
-
14
- require_relative '../example_helper'
15
-
16
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
17
- Prawn::ManualBuilder::Example.generate(filename) do
18
- text "Let's see which is the current font_size: #{font_size.inspect}"
19
-
20
- move_down 10
21
- font_size 16
22
- text 'Yeah, something bigger!'
23
-
24
- move_down 10
25
- font_size(25) { text 'Even bigger!' }
26
-
27
- move_down 10
28
- text 'Back to 16 again.'
29
-
30
- move_down 10
31
- text 'Single line on 20 using the :size option.', size: 20
32
-
33
- move_down 10
34
- text 'Back to 16 once more.'
35
-
36
- move_down 10
37
- font('Courier', size: 10) do
38
- text 'Yeah, using Courier 10 courtesy of the font method.'
39
- end
40
-
41
- move_down 10
42
- font('Helvetica', size: 12)
43
- text 'Back to normal'
44
- end
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- # Most font families come with some styles other than normal. Most common are
4
- # <code>bold</code>, <code>italic</code> and <code>bold_italic</code>.
5
- #
6
- # The style can be set the using the <code>:style</code> option, with either the
7
- # <code>font</code> method which will set the font and style for rest of the
8
- # document, or with the inline text methods.
9
-
10
- require_relative '../example_helper'
11
-
12
- filename = File.basename(__FILE__).gsub('.rb', '.pdf')
13
- Prawn::ManualBuilder::Example.generate(filename) do
14
- %w[Courier Helvetica Times-Roman].each do |example_font|
15
- move_down 20
16
-
17
- %i[bold bold_italic italic normal].each do |style|
18
- font example_font, style: style
19
- text "I'm writing in #{example_font} (#{style})"
20
- end
21
- end
22
- end