Sha256: 59b8c939230bf4c7788336894785c7c95bfc85537bbaecb5b2fc62bd64dc180e
Contents?: true
Size: 828 Bytes
Versions: 1
Compression:
Stored size: 828 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| if is_pdf?(doc) doc else tempdir = File.join(Dir.tmpdir, 'docsplit') extract_pdf([doc], {:output => tempdir}) File.join(tempdir, File.basename(doc, File.extname(doc)) + '.pdf') end end end def is_pdf?(doc) File.extname(doc).downcase == '.pdf' || File.open(doc, 'rb', &:readline).force_encoding("BINARY") =~ /\A\%PDF-\d+(\.\d+)?/ end end extend TransparentPDFs end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
luccasmaso-docsplit-0.7.4.2 | lib/docsplit/transparent_pdfs.rb |