Module: PdfCover::ClassMethods::Paperclip

Defined in:
lib/pdf_cover.rb

Instance Method Summary collapse

Instance Method Details

#pdf_cover_attachment(attachment_name, options = {}) ⇒ Object

Adds a new attached file to the caller that has the pdf cover processors prepended to the list of processors given.

described in the Paperclip documentation for attachments are needed for this one. are passed to the has_attached_file call with just a new processor prepended to the given ones. The PdfCover processor will use the quality provided in the ‘convert_options` option when generating the jpeg.

Examples:

A sample ActiveRecord model with a pdf_cover attachment:

class WithPaperclip < ActiveRecord::Base
  include PdfCover

  pdf_cover_attachment :pdf, styles: { pdf_cover: ['', :jpeg]},
    convert_options: { all: '-quality 95 -density 300' }

  # Note that you must set content type validation as required by Paperclip
  validates_attachment_content_type :pdf, content_type: %w(application/pdf)
end

Parameters:

  • attachment_name (Symbol)

    the name of the new attachment. The fields

  • options (Hash) (defaults to: {})

    the same options that are accepted by Paperclip, they



63
64
65
66
67
# File 'lib/pdf_cover.rb', line 63

def pdf_cover_attachment(attachment_name, options = {})
  options[:processors] = (options[:processors] || []).unshift(:pdf_cover_processor)

  has_attached_file attachment_name, options
end