Class: Asciidoctor::PDF::Optimizer
- Defined in:
- lib/asciidoctor/pdf/optimizer.rb
Instance Attribute Summary collapse
-
#compatibility_level ⇒ Object
readonly
Returns the value of attribute compatibility_level.
-
#compliance ⇒ Object
readonly
Returns the value of attribute compliance.
-
#quality ⇒ Object
readonly
Returns the value of attribute quality.
Instance Method Summary collapse
-
#initialize(quality = 'default', compatibility_level = '1.4', compliance = 'PDF') ⇒ Optimizer
constructor
A new instance of Optimizer.
- #optimize_file(target) ⇒ Object
Constructor Details
#initialize(quality = 'default', compatibility_level = '1.4', compliance = 'PDF') ⇒ Optimizer
Returns a new instance of Optimizer.
52 53 54 55 56 57 58 59 |
# File 'lib/asciidoctor/pdf/optimizer.rb', line 52 def initialize quality = 'default', compatibility_level = '1.4', compliance = 'PDF' @quality = QUALITY_NAMES[quality] @compatibility_level = compatibility_level @compliance = compliance if (gs_path = ::ENV['GS']) ::RGhost::Config::GS[:path] = gs_path end end |
Instance Attribute Details
#compatibility_level ⇒ Object (readonly)
Returns the value of attribute compatibility_level.
49 50 51 |
# File 'lib/asciidoctor/pdf/optimizer.rb', line 49 def compatibility_level @compatibility_level end |
#compliance ⇒ Object (readonly)
Returns the value of attribute compliance.
50 51 52 |
# File 'lib/asciidoctor/pdf/optimizer.rb', line 50 def compliance @compliance end |
#quality ⇒ Object (readonly)
Returns the value of attribute quality.
48 49 50 |
# File 'lib/asciidoctor/pdf/optimizer.rb', line 48 def quality @quality end |
Instance Method Details
#optimize_file(target) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/asciidoctor/pdf/optimizer.rb', line 61 def optimize_file target ::Dir::Tmpname.create ['asciidoctor-pdf-', '.pdf'] do |tmpfile| filename_o = ::Pathname.new target filename_tmp = ::Pathname.new tmpfile if (pdfmark = filename_o.sub_ext '.pdfmark').file? inputs = [target, pdfmark.to_s].join ::File::PATH_SEPARATOR else inputs = target end d = { CannotEmbedFontPolicy: '/Warning', CompatibilityLevel: @compatibility_level, NEWPDF: false, Printed: false } case @compliance when 'PDF/A', 'PDF/A-1', 'PDF/A-2', 'PDF/A-3' d[:PDFA] = ((@compliance.split '-', 2)[1] || 1).to_i d[:ShowAnnots] = false when 'PDF/X', 'PDF/X-1', 'PDF/X-3' d[:PDFX] = true d[:ShowAnnots] = false end (::RGhost::Convert.new inputs).to :pdf, filename: filename_tmp.to_s, quality: @quality, d: d filename_o.binwrite filename_tmp.binread end nil end |