asciidoctor-pdf 1.5.2 → 1.6.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.adoc +68 -1
  3. data/{LICENSE.adoc → LICENSE} +3 -4
  4. data/NOTICE.adoc +4 -6
  5. data/README.adoc +139 -46
  6. data/asciidoctor-pdf.gemspec +11 -14
  7. data/bin/asciidoctor-pdf-optimize +1 -1
  8. data/docs/theming-guide.adoc +26 -22
  9. data/lib/asciidoctor/pdf/converter.rb +88 -78
  10. data/lib/asciidoctor/pdf/ext/asciidoctor/section.rb +3 -2
  11. data/lib/asciidoctor/pdf/ext/core/file.rb +4 -5
  12. data/lib/asciidoctor/pdf/ext/core.rb +0 -1
  13. data/lib/asciidoctor/pdf/ext/pdf-core/pdf_object.rb +1 -1
  14. data/lib/asciidoctor/pdf/ext/pdf-core.rb +15 -0
  15. data/lib/asciidoctor/pdf/ext/prawn/coderay_encoder.rb +4 -13
  16. data/lib/asciidoctor/pdf/ext/prawn/extensions.rb +28 -2
  17. data/lib/asciidoctor/pdf/ext/prawn/font_metric_cache.rb +1 -1
  18. data/lib/asciidoctor/pdf/ext/prawn/formatted_text/arranger.rb +15 -0
  19. data/lib/asciidoctor/pdf/ext/prawn/formatted_text/box.rb +28 -7
  20. data/lib/asciidoctor/pdf/ext/prawn-svg.rb +0 -1
  21. data/lib/asciidoctor/pdf/ext/prawn.rb +1 -0
  22. data/lib/asciidoctor/pdf/ext/pygments.rb +11 -9
  23. data/lib/asciidoctor/pdf/ext.rb +0 -1
  24. data/lib/asciidoctor/pdf/formatted_text/fragment_position_renderer.rb +5 -1
  25. data/lib/asciidoctor/pdf/formatted_text/inline_image_arranger.rb +9 -2
  26. data/lib/asciidoctor/pdf/formatted_text/transform.rb +6 -4
  27. data/lib/asciidoctor/pdf/index_catalog.rb +1 -1
  28. data/lib/asciidoctor/pdf/optimizer.rb +40 -12
  29. data/lib/asciidoctor/pdf/pdfmark.rb +1 -2
  30. data/lib/asciidoctor/pdf/text_transformer.rb +10 -71
  31. data/lib/asciidoctor/pdf/theme_loader.rb +1 -1
  32. data/lib/asciidoctor/pdf/version.rb +1 -1
  33. data/lib/asciidoctor/pdf.rb +3 -0
  34. metadata +21 -63
  35. data/lib/asciidoctor/pdf/ext/core/numeric.rb +0 -26
  36. data/lib/asciidoctor/pdf/ext/prawn-svg/interface.rb +0 -14
  37. data/lib/asciidoctor/pdf/ext/prawn-templates.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e90846d73d8139ce9e156f4010b8cd4220d9aa318897ec94dcac52ca2b027c61
4
- data.tar.gz: b519c77487cb7c7b317244342dcb06b40241d511016f6289e3a31b8305798225
3
+ metadata.gz: 38535fd62633525b00cea5277158ac23dbbd1bf515ee577ff867d7a498149b19
4
+ data.tar.gz: 24b2f3f50bb62f71416ce783fdd173e7574680ca445e4cd724f265086b2e8978
5
5
  SHA512:
6
- metadata.gz: 836351139245d4460ea72c91889276e86484b1f587681ada048ccfa8d0716b7bfb595f28de0862e24556faec53a1b412a5d5f65cf2236b7579523dfd785dd1a6
7
- data.tar.gz: ae3ca4fbc60ab2f8b0eefab691c8c08dfc2e39f20a2950516a8f2c4d6f9a09420f3b702b063d160592d389d390834148ef14ad173b4b31a8432995b926c27b14
6
+ metadata.gz: cb5e3a7117b597b3cc2f31ee013adbbf2415d6fa36893b5375e6a2aabffcdff456c72ecce0800a1cff43a637259c1c94321338fc626bb936c38841ce87909015
7
+ data.tar.gz: 7a18ab5e3d91cd6c9e1a99d2bd6885beaf329a249144e82a37fbfecbd784aae3758760c9695a82ef44304c951892d76113aad6737c11f720f888a552f00e18ab
data/CHANGELOG.adoc CHANGED
@@ -3,7 +3,74 @@
3
3
  :uri-repo: https://github.com/asciidoctor/asciidoctor-pdf
4
4
 
5
5
  This document provides a high-level view of the changes to the {project-name} by release.
6
- For a detailed view of what has changed, refer to the {uri-repo}/commits/master[commit history] on GitHub.
6
+ For a detailed view of what has changed, refer to the {uri-repo}/commits/v1.6.x[commit history] on GitHub.
7
+
8
+ == 1.6.1 (2021-09-04) - @mojavelinux
9
+
10
+ Enhancements::
11
+
12
+ * align footnotes block to the bottom of the page it is placed on (#1833)
13
+
14
+ Bug Fixes::
15
+
16
+ * patch Prawn to preserve leading null character when running on Ruby 3; preserves inline anchors when text is split by page (#1963)
17
+
18
+ == 1.6.0 (2021-05-10) - @mojavelinux
19
+
20
+ Enhancements::
21
+
22
+ * allow path of ghostscript command to be controlled using `GS` env var (#1791)
23
+
24
+ Bug Fixes::
25
+
26
+ * do not hyphenate a hyphen when hyphenation is enabled (#1562)
27
+
28
+ Compliance::
29
+
30
+ * add support for Ruby 3 and drop support for Ruby < 2.5 and JRuby < 9.2 (#1681)
31
+ * upgrade to Prawn 2.4.0 (adds support for Ruby 3)
32
+ * upgrade to prawn-svg 0.32 (adds support for Ruby 3 without a patch and for loading embedded images from a data URI)
33
+ * upgrade to prawn-icon 3.0.x
34
+ * release lock on ttfunk version (1.6 produces slightly different output from 1.5 for certain missing glyphs)
35
+ * drop support for Asciidoctor < 2 (#1552)
36
+
37
+ Build / Infrastructure::
38
+
39
+ * run tests against pygments.rb 2.x in addition to pygments.rb 1.2.0
40
+
41
+ == 1.5.4 (2021-01-09) - @mojavelinux
42
+
43
+ Bug Fixes::
44
+
45
+ * restore compatibility with Asciidoctor 2.0.12 when using Pygments (#1846)
46
+ * fix numeric assertions in test suite (#1542)
47
+ * keep caption with image when image is scaled down to fit page (#1803)
48
+ * prevent inline image from rendering multiple times if fallback font is used for alt text (#1858)
49
+ * disable cache tests if open-uri-cache gem is not available
50
+ * disable hyphen tests if text-hyphen gem is not available
51
+ * compensate for change in how character_spacing is applied in FontMetricCache#width_of after Prawn 2.2.2
52
+ * allow inline image to be enclosed in link macro (alt text was breaking parsing)
53
+ * use oembed API over HTTPS to get thumbnail for Vimeo video
54
+ * use conum font family defined in theme for conum in verbatim block (#1611)
55
+ * patch float precision constant so prawn-table does not fail to arrange cells that span columns (#1835)
56
+ * resolve images in theme correctly when theme is loaded from classloader (JRuby only) (#1829)
57
+
58
+ Compliance::
59
+
60
+ * upgrade to prawn-svg 0.31 (adds support for loading embedded images from a data URI) (#1810)
61
+
62
+ Build / Infrastructure::
63
+
64
+ * migrate Linux CI jobs to GitHub Actions
65
+
66
+ == 1.5.3 (2020-02-28) - @mojavelinux
67
+
68
+ Bug Fixes::
69
+
70
+ * do not hyphen a hyphen when hyphenation is enabled (#1562)
71
+ * fix crash when applying text transform to heading cell in table body (#1575)
72
+ * honor font style when looking for glyph in font
73
+ * only suggest installing prawn-gmagick gem if not loaded (#1578)
7
74
 
8
75
  == 1.5.2 (2020-02-21) - @mojavelinux
9
76
 
@@ -1,6 +1,6 @@
1
- .The MIT License
2
- ....
3
- Copyright (C) 2014-2020 OpenDevise Inc. and the Asciidoctor Project
1
+ MIT License
2
+
3
+ Copyright (C) 2014-present OpenDevise Inc. and the Asciidoctor Project
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  THE SOFTWARE.
22
- ....
data/NOTICE.adoc CHANGED
@@ -1,7 +1,7 @@
1
1
  = Asciidoctor PDF
2
2
  OpenDevise Inc.; Asciidoctor Project
3
3
 
4
- Copyright (C) 2014-2020 OpenDevise Inc. and the Asciidoctor Project.
4
+ Copyright (C) 2014-present OpenDevise Inc. and the Asciidoctor Project.
5
5
 
6
6
  Please visit the Asciidoctor project site for more information:
7
7
 
@@ -54,11 +54,9 @@ RomanNumeral class::
54
54
 
55
55
  - https://github.com/AndrewVos/roman-numerals
56
56
 
57
- PrawnCodeRayEncoder class::
58
- The PrawnCodeRayEncoder class, which is used for syntax highlighting source code for use with Prawn, is borrowed from the Prawn project and modified for the purpose of this application.
59
- The PrawnEncoder was written by Felipe Doria and is licensed under the GPLv3 license.
60
-
61
- http://www.gnu.org/licenses/gpl-3.0.html
57
+ Asciidoctor::Prawn::CodeRayEncoder class::
58
+ The Asciidoctor::Prawn::CodeRayEncoder class, which is used for syntax highlighting source code for use with Prawn, is borrowed from the Prawn project and modified for the purpose of this application.
59
+ The PrawnEncoder was written by Felipe Doria and may be used under Matz's original licensing terms for Ruby, the GPLv2 license, or the GPLv3 license.
62
60
 
63
61
  - https://github.com/prawnpdf/prawn
64
62
 
data/README.adoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = Asciidoctor PDF: A native PDF converter for AsciiDoc
2
2
  Dan Allen <https://github.com/mojavelinux[@mojavelinux]>; Sarah White <https://github.com/graphitefriction[@graphitefriction]>
3
- v1.5.2, 2020-02-21
3
+ v1.6.1, 2021-09-04
4
4
  // Settings:
5
5
  :experimental:
6
6
  :idprefix:
@@ -23,7 +23,8 @@ endif::[]
23
23
  :project-name: Asciidoctor PDF
24
24
  :project-handle: asciidoctor-pdf
25
25
  // Variables:
26
- :release-version: 1.5.2
26
+ :release-line: 1.6.x
27
+ :release-version: 1.6.1
27
28
  // URIs:
28
29
  :url-asciidoctor: http://asciidoctor.org
29
30
  :url-gem: http://rubygems.org/gems/asciidoctor-pdf
@@ -39,10 +40,9 @@ endif::[]
39
40
  :url-graphicsmagick: http://www.graphicsmagick.org
40
41
 
41
42
  ifdef::status[]
42
- image:https://img.shields.io/travis/asciidoctor/asciidoctor-pdf/master.svg[Build Status (Travis CI),link=https://travis-ci.org/asciidoctor/asciidoctor-pdf]
43
- image:https://github.com/asciidoctor/asciidoctor-pdf/workflows/CI/badge.svg[Build Status (GitHub Actions),link=https://github.com/asciidoctor/asciidoctor-pdf/actions?query=workflow%3ACI]
43
+ image:https://img.shields.io/badge/zulip-join_chat-brightgreen.svg[project chat,link=https://asciidoctor.zulipchat.com/]
44
+ image:{url-project-repo}/workflows/CI/badge.svg?branch=v{release-line}[Build Status (GitHub Actions),link={url-project-repo}/actions?query=workflow%3ACI+branch%3Av{release-line}]
44
45
  image:https://img.shields.io/gem/v/asciidoctor-pdf.svg[Latest Release, link={url-gem}]
45
- image:https://img.shields.io/badge/license-MIT-blue.svg[MIT License, link=#copyright]
46
46
  endif::[]
47
47
 
48
48
  Asciidoctor PDF is a native PDF converter for AsciiDoc.
@@ -50,6 +50,12 @@ It bypasses the requirement to generate an intermediary format such as DocBook,
50
50
  Instead, you can use this extension to convert your documents directly from AsciiDoc to PDF.
51
51
  Its aim is to take the pain out of creating PDF documents from AsciiDoc.
52
52
 
53
+ NOTE: You're viewing the documentation for the {release-line} release line.
54
+ If you're looking for the documentation for another release line, please refer to one of the following branches: +
55
+ {url-project-repo}/tree/main#readme[2.0.x]
56
+ &hybull;
57
+ {url-project-repo}/tree/v1.5.x#readme[1.5.x]
58
+
53
59
  toc::[]
54
60
 
55
61
  == Overview
@@ -71,7 +77,7 @@ But don't miss the <<Highlights>> to get a preview of what's possible.
71
77
 
72
78
  * Direct AsciiDoc to PDF conversion
73
79
  * <<docs/theming-guide.adoc#,Configuration-driven theme (style and layout)>>
74
- * Custom (TTF) fonts
80
+ * Custom fonts (TTF or OTF)
75
81
  * Full SVG support (thanks to https://github.com/mogest/prawn-svg[prawn-svg])
76
82
  * PDF document outline (i.e., bookmarks)
77
83
  * Title page
@@ -98,7 +104,7 @@ But don't miss the <<Highlights>> to get a preview of what's possible.
98
104
  == Known Limitations
99
105
 
100
106
  * Footnotes are always rendered as endnotes (at end of chapter for books; at end of document for all other doctypes)
101
- * Table cells that exceed height of a single page will be truncated (see https://github.com/prawnpdf/prawn-table/issues/41[prawn-table#41])
107
+ * Table cells that exceed the height of a single page will be truncated (see https://github.com/prawnpdf/prawn-table/issues/41[prawn-table#41])
102
108
  * Inline images in table cells must fit within available space or Prawn::Errors::CannotFit error will be thrown
103
109
  * Columns cannot be assigned a 0% width (or a width less than the width of a single character); in the same vein, a column cannot be set to autowidth if width of all other columns meets or exceeds 100%; the result is that the converter with throw a Prawn::Errors::CannotFit error
104
110
  * An inline image in a table cell will not force the column wider if the width of the image exceeds the width of the column; either reduce the image width using `pdfwidth` or increase the width of the column using `cols`; another solution is to convert the cell to an AsciiDoc table cell (see https://github.com/asciidoctor/asciidoctor-pdf/issues/830)
@@ -113,15 +119,29 @@ But don't miss the <<Highlights>> to get a preview of what's possible.
113
119
 
114
120
  == Prerequisites
115
121
 
116
- All that's needed is Ruby 2.3 or better and a few Ruby gems (including at least Asciidoctor 1.5.3), which we explain how to install in the next section.
122
+ All that's needed is Ruby (Ruby 2.5 or better) and a few Ruby gems (including at least Asciidoctor 2.0.0), which we explain how to install in the next section.
117
123
 
118
124
  To check if you have Ruby available, use the `ruby` command to query the version installed:
119
125
 
120
126
  $ ruby --version
121
127
 
122
- Make sure this command reports a Ruby version that's at least 2.3.
128
+ Make sure this command reports a Ruby version that's at least 2.5.
123
129
  If so, you may proceed.
124
130
 
131
+ If you want to <<Enable Stream Compression,optimize the pdf>> using rghost or hexapdf, you'll need to install the rghost gem:
132
+
133
+ $ gem install rghost
134
+
135
+ or the hexapdf gem:
136
+
137
+ $ gem install hexapdf
138
+
139
+ Similarly, if you want to use the hyphen option you will need to install the `text-hyphen` gem:
140
+
141
+ $ gem install text-hyphen
142
+
143
+ You'll also need to <<Install a Syntax Highlighter (optional),install a syntax highlighter>> to use source highlighting.
144
+
125
145
  === System Encoding
126
146
 
127
147
  Asciidoctor assumes you're using UTF-8 encoding.
@@ -164,7 +184,7 @@ All files are managed in user space (aka your home or user directory).
164
184
  If something gets messed up, you can simply remove the [.path]_$HOME/.rvm_ folder and start over.
165
185
 
166
186
  To learn how to install RVM, follow the https://asciidoctor.org/docs/install-asciidoctor-macos/#rvm-procedure-recommended[RVM installation procedure] covered in the Asciidoctor documentation.
167
- Once you have installed RVM and used it to install Ruby, make sure to activate the Ruby managed by RVM using `rvm use default` or a specific Ruby version like `rvm use 2.6`.
187
+ Once you have installed RVM and used it to install Ruby, make sure to activate the Ruby managed by RVM using `rvm use default` or a specific Ruby version like `rvm use 2.7`.
168
188
  (You'll need to do this each time you open a new terminal).
169
189
 
170
190
  After installing the gem, you can see where it was installed using the following command:
@@ -202,12 +222,12 @@ You then activate syntax highlighting for a given document by adding the `source
202
222
  ==== Upgrade Prawn and Extensions (optional)
203
223
 
204
224
  {project-name} uses Prawn to handle the PDF generation, which has a different release cycle.
205
- At times, there may are development features in Prawn and its extensions you need to use which haven't yet been released.
225
+ At times, there may be development features in Prawn and its extensions you need to use which haven't yet been released.
206
226
  No problem.
207
227
  You can still gain access to these features by installing the unreleased gems directly from GitHub.
208
228
 
209
229
  To get started, first create a [.path]_Gemfile_ in the root of your project.
210
- In that file, declare the gem soruce, the {project-handle} gem, and the prawn gem and/or one of its extension gems.
230
+ In that file, declare the gem source, the {project-handle} gem, and the prawn gem and/or one of its extension gems.
211
231
  In this example, we'll install both the prawn and prawn-table gems from GitHub.
212
232
 
213
233
  .Gemfile
@@ -262,7 +282,7 @@ It's time to convert the AsciiDoc document directly to PDF.
262
282
 
263
283
  IMPORTANT: You'll need the `rouge` gem installed to run this example since it uses the `source-highlighter` attribute with the value of `rouge`.
264
284
 
265
- Converting to PDF is a simple as running the `asciidoctor-pdf` script using Ruby and passing our AsciiDoc document as the first argument.
285
+ Converting to PDF is as simple as running the `asciidoctor-pdf` script using Ruby and passing our AsciiDoc document as the first argument.
266
286
 
267
287
  $ asciidoctor-pdf basic-example.adoc
268
288
 
@@ -288,7 +308,7 @@ The pain of the DocBook toolchain should be melting away about now.
288
308
  == Themes
289
309
 
290
310
  The layout and styling of the PDF is driven by a YAML configuration file.
291
- To learn how the theming system works and how to create and apply custom themes, refer to the <<docs/theming-guide.adoc#,Asciidoctor PDF Theme Guide>>.
311
+ To learn how the theming system works and how to create and apply custom themes, refer to the <<docs/theming-guide.adoc#,Asciidoctor PDF Theming Guide>>.
292
312
  You can use the built-in theme files, which you can find in the [.path]_data/themes_ directory, as examples.
293
313
 
294
314
  If you've enabled a source highlighter, you can control the style (aka theme) it applies to source blocks using the `coderay-style`, `pygments-style`, and `rouge-style` attributes, respectively.
@@ -297,7 +317,7 @@ For example, to configure Rouge to use the built-in monokai theme, run Asciidoct
297
317
  $ asciidoctor-pdf -a rouge-style=monokai basic-example.adoc
298
318
 
299
319
  It's possible to develop your own theme for Rouge.
300
- Refer to the <<docs/theming-guide.adoc#,Asciidoctor PDF Theme Guide>> for details.
320
+ Refer to the <<docs/theming-guide.adoc#,Asciidoctor PDF Theming Guide>> for details.
301
321
 
302
322
  == Support for Non-Latin Languages
303
323
 
@@ -305,7 +325,7 @@ Asciidoctor can process the full range of characters in the UTF-8 character set.
305
325
  That means you can write your document in any language, save the file with UTF-8 encoding (_that's important!_), and expect Asciidoctor to convert the text properly.
306
326
  But you still need a font that provides the glyphs for those characters.
307
327
 
308
- When converting a document with Asciidoctor PDF, you may notice that some of the glyphs for certain languages, such as Chinese, are missing from the PDF.
328
+ When converting a document with Asciidoctor PDF, you may notice that some glyphs for certain languages, such as Chinese, are missing from the PDF.
309
329
  PDF is a "`bring your own font`" kind of system.
310
330
  In other words, the font you provide must provide glyphs for all the characters used.
311
331
  There's no one font that supports all the world's languages (though some, like Noto Serif, certainly come close).
@@ -468,15 +488,10 @@ Otherwise, the SVG library will fail to process it.
468
488
 
469
489
  === Asciidoctor Diagram Integration
470
490
 
471
- As of Asciidoctor PDF 1.5.0.alpha.17 running on Asciidoctor 2 or better, Asciidoctor PDF provides better integration with Asciidoctor Diagram by setting the `data-uri` attribute by default.
491
+ Asciidoctor PDF provides seamless integration with Asciidoctor Diagram by setting the `data-uri` attribute by default.
472
492
  When the `data-uri` attribute is set, Asciidoctor Diagram returns the absolute path to the generated image, which Asciidoctor PDF can then locate.
473
493
  (This makes sense since technically, Asciidoctor Diagram must embed the image in the document, similar in spirit to the `data-uri` feature for HTML).
474
- This means the input directory and the output directory (and thus the imagesoutdir) can differ and Asciidoctor PDF will still be able to locate the generate image.
475
-
476
- Prior to Asciidoctor PDF 1.5.0.alpha.17 (or prior to Asciidoctor 2), the way to solve this problem is to set the `imagesdir` attribute to an absolute path.
477
- That way, it won't matter where the generated image is written.
478
- Asciidoctor PDF will still be able to find it.
479
- Keep in mind that this strategy may introduce other side effects you'll have to work around.
494
+ This means the input directory and the output directory (and thus the imagesoutdir) can differ and Asciidoctor PDF will still be able to locate the generated image.
480
495
 
481
496
  == Image Scaling
482
497
 
@@ -541,9 +556,9 @@ The pdfwidth attribute supports the following units:
541
556
 
542
557
  In all cases, the width is converted to pt.
543
558
 
544
- === Specifying a default width
559
+ === Specifying a Default Width
545
560
 
546
- If you want to scale all block images that don't have a pdfwidth or scaledwidth attribute specified, assign a value to the image_width key in your theme.
561
+ To scale all block images that don't define either a `pdfwidth` or `scaledwidth` attribute on the image macro, assign a value to the image-width key in your theme file.
547
562
 
548
563
  [source,yaml]
549
564
  ----
@@ -551,6 +566,10 @@ image:
551
566
  width: 100%
552
567
  ----
553
568
 
569
+ The image-width key accepts the same values as the `pdfwidth` attribute.
570
+ Thus, you can think of it as the fallback value for the `pdfwidth` attribute.
571
+ If specified, this value takes precedence over the `width` attribute on the image macro.
572
+
554
573
  === Inline Image Sizing
555
574
 
556
575
  Inline images can be sized in much the same way as block images (using the pdfwidth, scaledwidth or width attributes), with the following exceptions:
@@ -571,7 +590,7 @@ If the image height exceeds the height of the page, the image will be scaled dow
571
590
 
572
591
  In addition to the width-related attributes previously covered, cover and background images can be sized relative to the page using the `fit` attribute of the image macro.
573
592
  The `fit` attribute works similarly to the `object-fit` property in CSS.
574
- It's value must be specified as a single keyword, chosen from the table below.
593
+ Its value must be specified as a single keyword, chosen from the table below.
575
594
  The starting size of the image is determined by the explicit width, if specified, or the implicit width.
576
595
  The height is always derived from the width while respecting the implicit aspect ratio of the image.
577
596
  The available space for a background image (i.e., the canvas) is the page.
@@ -889,7 +908,7 @@ Here's an example of how to skip a passthrough block when converting to PDF:
889
908
  \endif::[]
890
909
  ----
891
910
 
892
- Here's an example of how to only enable a passthrough block when convertering to HTML5:
911
+ Here's an example of how to only enable a passthrough block when converting to HTML5:
893
912
 
894
913
  [source,asciidoc]
895
914
  ----
@@ -1011,7 +1030,7 @@ This value is used as the heading of the preface and as the text of the entry in
1011
1030
 
1012
1031
  Asciidoctor PDF supports generating an index catalog that itemizes all index terms defined in the document, allowing the reader to navigate the document by keyword.
1013
1032
 
1014
- To get Asciidoctor PDF to generate an index, simply add an level-1 section flagged with the `index` style near the end of your document.
1033
+ To get Asciidoctor PDF to generate an index, add a level-1 section flagged with the `index` style near the end of your document.
1015
1034
  The converter will automatically populate the catalog with the list of index terms in the document, organized by first letter.
1016
1035
 
1017
1036
  [source,asciidoc]
@@ -1028,39 +1047,74 @@ However, you could use an extension, such as a TreeProcessor, to automatically m
1028
1047
 
1029
1048
  == Optimizing the Generated PDF
1030
1049
 
1031
- By default, Asciidoctor PDF does not optimize the output document or even compress the streams.
1032
- The simplest way to reduce the size of the file is to enable stream compression (using the FlateDecode method).
1050
+ By default, Asciidoctor PDF does not optimize the PDF it generates or compress its streams.
1051
+ This section covers several approaches you can take to optimize your PDF.
1052
+
1053
+ === Enable Stream Compression
1054
+
1055
+ The simplest way to reduce the size of the PDF file is to enable stream compression (using the FlateDecode method).
1033
1056
  You can enable this feature by setting the `compress` attribute on the document:
1034
1057
 
1035
1058
  $ asciidoctor-pdf -a compress document.adoc
1036
1059
 
1037
- For more thorough optimzation, you can use either the built-in `asciidoctor-pdf-optimize` script or hexapdf.
1060
+ For a more thorough optimization, you can use the integrated optimizer or hexapdf.
1038
1061
  Read on to learn how.
1039
1062
 
1040
- === asciidoctor-pdf-optimize
1063
+ === rghost
1041
1064
 
1042
- {project-name} also provides a bin script that uses GhostScript to optimize and compress the generated PDF (with minimal impact on quality).
1065
+ {project-name} also provides a flag (and bin script) that uses GhostScript (via rghost) to optimize and compress the generated PDF (with minimal impact on quality).
1043
1066
  You must have Ghostscript (command: `gs`) and the `rghost` gem installed to use it.
1044
1067
 
1045
- Here's an example usage:
1068
+ Here's an example usage that converts your document and optimizes it:
1069
+
1070
+ $ asciidoctor-pdf -a optimize basic-example.adoc
1071
+
1072
+ The command will generate an optimized PDF 1.4 file.
1073
+ In addition to optimizing the PDF file, it also converts it from plain PDF to a PDF/X-1a.
1074
+
1075
+ If this command fails because the `gs` command cannot be found, you'll need to set it using the `GS` environment variable.
1076
+ On Windows, this step is almost always required since the Ghostscript installer does not install the `gs` command into a standard location.
1077
+ Here's an example that shows how you can override the `gs` command path:
1078
+
1079
+ $ GS=/path/to/gs asciidoctor-pdf -a optimize basic-example.adoc
1080
+
1081
+ You'll need to use the technique for assigning an environment variable that's relevant for your system.
1082
+
1083
+ The one limitation of generating a PDF/X-1a file is that it does not allow non-ASCII characters in the document metadata fields (i.e., title, author, subject, etc).
1084
+ To workaround this limitation, you can force Ghostscript to generate a PDF 1.3 file using the `pdf-version` attribute:
1085
+
1086
+ $ asciidoctor-pdf -a optimize -a pdf-version=1.3 basic-example.adoc
1087
+
1088
+ CAUTION: Downgrading the PDF version may break the PDF if it contains an image that uses color blending or transparency.
1089
+ Specifically, the text on the page can become rasterized, which causes links to stop working and prevents text from being selected.
1090
+ If you're in this situation, it might be best to try <<hexapdf>> instead.
1091
+
1092
+ If you're looking for a smaller file size, you can try reducing the quality of the output file by passing a quality keyword to the `optimize` attribute (e.g., `--optimize=screen`).
1093
+ The `optimize` attribute accepts the following keywords: `default` (default, same if value is empty), `screen`, `ebook`, `printer`, and `prepress`.
1094
+ Refer to the https://www.ghostscript.com/doc/current/VectorDevices.htm#PSPDF_IN[Ghostscript documentation^] to learn what settings these presets affect.
1095
+
1096
+ If you've already generated the PDF, and want to optimize it directly, you can use the bin script:
1046
1097
 
1047
1098
  $ asciidoctor-pdf-optimize basic-example.pdf
1048
1099
 
1049
1100
  The command will overwrite the PDF file with an optimized version.
1101
+ You can also try reducing the quality of the output file using the `--quality` flag (e.g., `--quality screen`).
1102
+ The `--quality` flag accepts the following keywords: `default` (default), `screen`, `ebook`, `printer`, and `prepress`.
1050
1103
 
1051
- If a file is found with the extension `.pdfmark` and the same rootname as the input file, it is used to add metadata to the generated PDF document.
1052
- This file is necessary to preserve the document metadata since Ghostscript will otherwise drop it.
1053
- That's why {project-name} always creates this file in addition to the PDF.
1104
+ In both cases, if a file is found with the extension `.pdfmark` and the same rootname as the input file, it will be used to add metadata to the generated PDF document.
1105
+ This file is necessary when using versions of Ghostscript < 8.54, which did not automatically preserve this metadata.
1106
+ You can instruct the converter to automatically generate a pdfmark file by setting the `pdfmark` attribute (i.e., `-a pdfmark`)
1107
+ When using a more recent version of Ghostscript, you do not need to generate a `.pdfmark` file for this purpose.
1054
1108
 
1055
1109
  IMPORTANT: The `asciidoctor-pdf-optimize` is not guaranteed to reduce the size of the PDF file.
1056
1110
  It may actually make the PDF larger.
1057
1111
  You should probably only consider using it if the file size of the original PDF is several megabytes.
1058
- You can also try reducing the quality of the output file using the `--quality` flag (e.g., `--quality screen`).
1059
- The `--quality` flag accepts the following keywords: `default` (default), `screen`, `ebook`, `printer`, and `prepress`.
1112
+
1113
+ If you have difficulty getting the `rghost` gem installed, or you aren't getting the results you expect, you can try the optimizer provided by hexapdf instead.
1060
1114
 
1061
1115
  === hexapdf
1062
1116
 
1063
- Another option to optimize the PDF is https://hexapdf.gettalong.org/[hexapdf] (gem: hexapdf, command: hexapdf).
1117
+ Another option to optimize the PDF is https://hexapdf.gettalong.org/[hexapdf^] (gem: hexapdf, command: hexapdf).
1064
1118
  Before introducing it, though, it's important to point out that its license is AGPL.
1065
1119
  If that's okay with you, read on to learn how to use it.
1066
1120
 
@@ -1070,17 +1124,56 @@ First, install the hexapdf gem using the following command:
1070
1124
 
1071
1125
  You can then use it to optimize your PDF as follows:
1072
1126
 
1073
- $ hexapdf optimize --compress-pages --force basic-example.pdf basic-example-optimized.pdf
1127
+ $ hexapdf optimize --compress-pages --force basic-example.pdf basic-example.pdf
1074
1128
 
1075
1129
  This command does not manipulate the images in any way.
1076
1130
  It merely compresses the objects in the PDF and prunes any unreachable references.
1077
- But given how much waste Prawn leaves behind, this turns out to reduce the file size significantly.
1131
+ But given how much waste Prawn leaves behind, this turns out to reduce the file size substantially.
1132
+
1133
+ You can hook this command directly into the converter by providing your own implementation of the `Optimizer` class.
1134
+ Start by creating a Ruby file named [.path]_optimizer-hexapdf.rb_, then populate it with the following code:
1135
+
1136
+ .optimizer-hexapdf.rb
1137
+ [source,ruby]
1138
+ ----
1139
+ require 'hexapdf/cli'
1140
+
1141
+ class Asciidoctor::PDF::Optimizer
1142
+ def initialize(*)
1143
+ app = HexaPDF::CLI::Application.new
1144
+ app.instance_variable_set :@force, true
1145
+ @optimize = app.main_command.commands['optimize']
1146
+ end
1147
+
1148
+ def optimize_file path
1149
+ options = @optimize.instance_variable_get :@out_options
1150
+ options.compress_pages = true
1151
+ #options.object_streams = :preserve
1152
+ #options.xref_streams = :preserve
1153
+ #options.streams = :preserve # or :uncompress
1154
+ @optimize.execute path, path
1155
+ nil
1156
+ rescue
1157
+ # retry without page compression, which can sometimes fail
1158
+ options.compress_pages = false
1159
+ @optimize.execute path, path
1160
+ nil
1161
+ end
1162
+ end
1163
+ ----
1164
+
1165
+ To activate your custom optimizer, load this file when invoking the `asciidoctor-pdf` using the `-r` flag and set the `optimize` attribute as well using the `-a` flag.
1166
+
1167
+ $ asciidoctor-pdf -r ./optimizer-hexapdf.rb -a optimize basic-example.adoc
1168
+
1169
+ Now you can convert and optimize all in one go.
1078
1170
 
1079
- To see more options, run:
1171
+ To see more options that `hexapdf optimize` offers, run:
1080
1172
 
1081
1173
  $ hexapdf help optimize
1082
1174
 
1083
- For example, to make the source of the PDF a bit more readable, set the stream-related options to `preserve`.
1175
+ For example, to make the source of the PDF a bit more readable (though less optimized), set the stream-related options to `preserve` (e.g.,, `--streams preserve` from the CLI or `options.streams = :preserve` from the API).
1176
+ You can also disable page compressioin (e.g., `--no-compress-pages` from the CLI or `options.compress_pages = false` from the API).
1084
1177
 
1085
1178
  hexapdf also allows you to add password protection to your PDF, if that's something you're interested in doing.
1086
1179
 
@@ -1101,8 +1194,8 @@ To help develop {project-name}, or to simply use the development version, refer
1101
1194
 
1102
1195
  == Copyright
1103
1196
 
1104
- Copyright (C) 2014-2020 OpenDevise Inc. and the Asciidoctor Project.
1197
+ Copyright (C) 2014-present OpenDevise Inc. and the Asciidoctor Project.
1105
1198
  Free use of this software is granted under the terms of the MIT License.
1106
1199
 
1107
- For the full text of the license, see the <<LICENSE.adoc#,LICENSE>> file.
1200
+ For the full text of the license, see the link:LICENSE[] file.
1108
1201
  Refer to the <<NOTICE.adoc#,NOTICE>> file for information about third-party Open Source software in use.