Class: Pdf::Compressor
- Inherits:
-
BaseService
- Object
- BaseService
- Pdf::Compressor
- Defined in:
- app/services/pdf/compressor.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- PDF_SETTINGS =
%w[/screen /ebook /printer /prepress /default].freeze
- COMPATIBILITY_LEVELS =
%w[1.2 1.3 1.4 1.5 1.6 1.7].freeze
Instance Attribute Summary collapse
-
#compatibility_level ⇒ Object
readonly
Returns the value of attribute compatibility_level.
-
#input_blob ⇒ Object
readonly
Returns the value of attribute input_blob.
-
#input_path ⇒ Object
readonly
Returns the value of attribute input_path.
-
#output_blob ⇒ Object
readonly
Returns the value of attribute output_blob.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#pdf_setting ⇒ Object
readonly
Returns the value of attribute pdf_setting.
Instance Method Summary collapse
- #compress ⇒ Object
-
#initialize(input_path: nil, output_path: nil, input_blob: nil, output_blob: nil, compatibility_level: '1.4', pdf_setting: '/printer') ⇒ Compressor
constructor
A new instance of Compressor.
Methods inherited from BaseService
#log_debug, #log_error, #log_info, #log_warning, #logger, #options, #process, #tagged_logger
Constructor Details
#initialize(input_path: nil, output_path: nil, input_blob: nil, output_blob: nil, compatibility_level: '1.4', pdf_setting: '/printer') ⇒ Compressor
Returns a new instance of Compressor.
13 14 15 16 17 18 19 20 |
# File 'app/services/pdf/compressor.rb', line 13 def initialize(input_path: nil, output_path: nil, input_blob: nil, output_blob: nil, compatibility_level: '1.4', pdf_setting: '/printer') @input_path = input_path ? Shellwords.escape(input_path) : nil @output_path = output_path ? Shellwords.escape(output_path) : input_path @input_blob = input_blob @output_blob = output_blob @compatibility_level = validate_compatibility(compatibility_level) @pdf_setting = validate_pdf_setting(pdf_setting) end |
Instance Attribute Details
#compatibility_level ⇒ Object (readonly)
Returns the value of attribute compatibility_level.
5 6 7 |
# File 'app/services/pdf/compressor.rb', line 5 def compatibility_level @compatibility_level end |
#input_blob ⇒ Object (readonly)
Returns the value of attribute input_blob.
5 6 7 |
# File 'app/services/pdf/compressor.rb', line 5 def input_blob @input_blob end |
#input_path ⇒ Object (readonly)
Returns the value of attribute input_path.
5 6 7 |
# File 'app/services/pdf/compressor.rb', line 5 def input_path @input_path end |
#output_blob ⇒ Object (readonly)
Returns the value of attribute output_blob.
5 6 7 |
# File 'app/services/pdf/compressor.rb', line 5 def output_blob @output_blob end |
#output_path ⇒ Object (readonly)
Returns the value of attribute output_path.
5 6 7 |
# File 'app/services/pdf/compressor.rb', line 5 def output_path @output_path end |
#pdf_setting ⇒ Object (readonly)
Returns the value of attribute pdf_setting.
5 6 7 |
# File 'app/services/pdf/compressor.rb', line 5 def pdf_setting @pdf_setting end |
Instance Method Details
#compress ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/pdf/compressor.rb', line 22 def compress unless gs_available? handle_missing_gs return Result.new(result: :skipped, message: 'Ghostscript not available, file copied or left unchanged', input_path:, output_path:) end if input_blob compress_blob else compress_file end end |