Class: Paperclip::PdfCoverProcessor
- Inherits:
-
Processor
- Object
- Processor
- Paperclip::PdfCoverProcessor
- Defined in:
- lib/paperclip/pdf_cover_processor.rb
Overview
This is a Paperclip::Processor that can be used to generate an image from a PDF file. The image is only of the first page.
We inherit the following instance variables from Paperclip::Processor:
@file the file that will be operated on (which is an instance of File)
a hash of that were defined in has_attached_file's style hash
@attachment the Paperclip::Attachment itself
Constant Summary collapse
- QUALITY_CONVERT_OPTION_REGEX =
/-quality\s+(?<quality>\d+)/- RESOLUTION_CONVERT_OPTION_REGEX =
/-density\s+(?<resolution>\d+)/
Instance Method Summary collapse
- #converter_options ⇒ Object
- #extract_convert_option(key, regex) ⇒ Object
- #format ⇒ Object
- #jpeg_quality ⇒ Object
- #jpeg_resolution ⇒ Object
- #make ⇒ Object
Instance Method Details
#converter_options ⇒ Object
20 21 22 |
# File 'lib/paperclip/pdf_cover_processor.rb', line 20 def format.merge(jpeg_quality).merge(jpeg_resolution) end |
#extract_convert_option(key, regex) ⇒ Object
36 37 38 39 40 41 |
# File 'lib/paperclip/pdf_cover_processor.rb', line 36 def extract_convert_option(key, regex) match_data = regex.match([:convert_options]) match = match_data && match_data[key] match ? { key => match } : {} end |
#format ⇒ Object
24 25 26 |
# File 'lib/paperclip/pdf_cover_processor.rb', line 24 def format { format: [:format].to_s } end |
#jpeg_quality ⇒ Object
28 29 30 |
# File 'lib/paperclip/pdf_cover_processor.rb', line 28 def jpeg_quality extract_convert_option(:quality, QUALITY_CONVERT_OPTION_REGEX) end |
#jpeg_resolution ⇒ Object
32 33 34 |
# File 'lib/paperclip/pdf_cover_processor.rb', line 32 def jpeg_resolution extract_convert_option(:resolution, RESOLUTION_CONVERT_OPTION_REGEX) end |
#make ⇒ Object
16 17 18 |
# File 'lib/paperclip/pdf_cover_processor.rb', line 16 def make ::PdfCover::Converter.new(@file, ).converted_file end |