summaryrefslogtreecommitdiff
path: root/README.adoc
diff options
context:
space:
mode:
authorDan Allen <dan.j.allen@gmail.com>2020-10-29 02:39:27 -0600
committerDan Allen <dan.j.allen@gmail.com>2020-10-29 02:39:27 -0600
commitffed9db43bc99863041b3424e26e14905015d966 (patch)
tree3e88485c8db2495a63a7ef3e4619b95f77bb5029 /README.adoc
parent4d39943e1bd94aabbcd2754fec1b5cfe77a56b3f (diff)
use hexapdf API instead of CLI in hexapdf optimizer example in README [skip ci]
Diffstat (limited to 'README.adoc')
-rw-r--r--README.adoc23
1 files changed, 20 insertions, 3 deletions
diff --git a/README.adoc b/README.adoc
index 07a62f79..28f87792 100644
--- a/README.adoc
+++ b/README.adoc
@@ -1221,11 +1221,27 @@ Start by creating a Ruby file named [.path]_optimizer-hexapdf.rb_, then populate
.optimizer-hexapdf.rb
[source,ruby]
----
+require 'hexapdf/cli'
+
class Asciidoctor::PDF::Optimizer
- def initialize *; end
+ def initialize(*)
+ app = HexaPDF::CLI::Application.new
+ app.instance_variable_set :@force, true
+ @optimize = app.main_command.commands['optimize']
+ end
def optimize_file path
- system 'hexapdf', 'optimize', '--compress-pages', '--force', path, path, exception: true
+ options = @optimize.instance_variable_get :@out_options
+ options.compress_pages = true
+ #options.object_streams = :preserve
+ #options.xref_streams = :preserve
+ #options.streams = :preserve # or :uncompress
+ @optimize.execute path, path
+ nil
+ rescue
+ # retry without page compression, which can sometimes fail
+ options.compress_pages = false
+ @optimize.execute path, path
nil
end
end
@@ -1241,7 +1257,8 @@ To see more options that `hexapdf optimize` offers, run:
$ hexapdf help optimize
-For example, to make the source of the PDF a bit more readable, set the stream-related options to `preserve` (i.e., `--streams preserve`).
+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).
+You can also disable page compressioin (e.g., `--no-compress-pages` from the CLI or `options.compress_pages = false` from the API).
hexapdf also allows you to add password protection to your PDF, if that's something you're interested in doing.