Sha256: 6f534fc1d6b572ac0a10280c9663da2f9a8c396349443f239a52132bc12a2c46

Contents?: true

Size: 701 Bytes

Versions: 6

Compression:

Stored size: 701 Bytes

Contents

module Docsplit

  # Include a method to transparently convert non-PDF arguments to temporary
  # PDFs. Allows us to pretend to natively support docs, rtf, ppt, and so on.
  module TransparentPDFs

    # Temporarily convert any non-PDF documents to PDFs before running them
    # through further extraction.
    def ensure_pdfs(docs)
      [docs].flatten.map do |doc|
        ext = File.extname(doc)
        if ext.downcase == '.pdf'
          doc
        else
          @tempdir ||= File.join(Dir.tmpdir, 'docsplit')
          extract_pdf([doc], {:output => @tempdir})
          File.join(@tempdir, File.basename(doc, ext) + '.pdf')
        end
      end
    end

  end

  extend TransparentPDFs

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
docsplit-0.3.1 lib/docsplit/transparent_pdfs.rb
docsplit-0.3.0 lib/docsplit/transparent_pdfs.rb
docsplit-0.2.0 lib/docsplit/transparent_pdfs.rb
docsplit-0.1.3 lib/docsplit/transparent_pdfs.rb
docsplit-0.1.2 lib/docsplit/transparent_pdfs.rb
docsplit-0.1.1 lib/docsplit/transparent_pdfs.rb