Sha256: 76ae324af3ef12bf050938b82f4881e8ee13f2ad2f7705f9159ac48878afea01
Contents?: true
Size: 1.46 KB
Versions: 1
Compression:
Stored size: 1.46 KB
Contents
module Gjman module PDF class Compressor < Base class << self def do(src, opts={}) default_dest = src.sub(/\.pdf$/, '-o.pdf') work(:compress, src, opts.delete(:to) || default_dest, default_dest) end def undo(src, opts={}) default_dest = src.sub(/\.pdf$/, '-u.pdf') work(:uncompress, src, opts.delete(:to) || default_dest, default_dest) end private def work(action, src, dest, tmp_dest) case send(action, src) when /Already compressed\. \(Force recompression with \-force\.\)/, /java\.lang\.ArrayIndexOutOfBoundsException/ File.copy(src, dest) else File.move(tmp_dest, dest) end dest end # NOTE: Since pdftk is almost as dead as multivalent (last updated in 2006), # there is really no good reason to choose it over multivalent. Moreover, # since pdf comparison requires java solution, it makes sense to be consistent, # which is essentially sticking to java. # # def do(src, dest) # pdftk(:compress, src, dest) # end # # def undo(src, dest) # pdftk(:uncompress, src, dest) # end # # def pdftk(mode, src, dest) # shell(:pdftk, [src, :output, dest, mode, :verbose]) # dest # end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
gjman-0.1.0 | lib/gjman/pdf/compressor.rb |