Module: PdfCover
- Defined in:
- lib/pdf_cover.rb,
lib/pdf_cover/version.rb,
lib/pdf_cover/converter.rb
Overview
This module provides methods for CarrierWave::Uploader::Base subclasses and for ActiveRecord models that want to include attachments to simplify the generation of JPEG images from the first page of a PDF file that is uploaded by the users. Include this module in your class and check the ‘ClassMethods` documentation that corresponds to your attachments managing library in this same file.
Defined Under Namespace
Modules: ClassMethods Classes: Converter
Constant Summary collapse
- VERSION =
"0.3.2".freeze
Class Method Summary collapse
Instance Method Summary collapse
- #enforce_content_type(content_type) ⇒ Object
-
#pdf_cover(quality, resolution) ⇒ Object
This is the method used by the CarrierWave processor mechanism.
Class Method Details
.included(base) ⇒ Object
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/pdf_cover.rb', line 72 def included(base) if carrierwave_defined?(base) base.extend ClassMethods::CarrierWave elsif paperclip_defined? require "paperclip/pdf_cover_processor" base.extend ClassMethods::Paperclip else fail "#{base} is not a CarrierWave::Uploader and Paperclip is not defined ¯\\_(ツ)_/¯" end end |
Instance Method Details
#enforce_content_type(content_type) ⇒ Object
101 102 103 |
# File 'lib/pdf_cover.rb', line 101 def enforce_content_type(content_type) file.content_type = content_type end |
#pdf_cover(quality, resolution) ⇒ Object
This is the method used by the CarrierWave processor mechanism
95 96 97 98 99 |
# File 'lib/pdf_cover.rb', line 95 def pdf_cover(quality, resolution) = { quality: quality, resolution: resolution }.compact converted_file = PdfCover::Converter.new(file, ).converted_file FileUtils.cp(converted_file, current_path) end |