Skip to content

Instantly share code, notes, and snippets.

@Krule
Created January 24, 2011 09:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Krule/793003 to your computer and use it in GitHub Desktop.
Save Krule/793003 to your computer and use it in GitHub Desktop.
Paperclip pdf2swf processor utilizing swftools
module Paperclip
class PdfToSwf < Processor
attr_accessor :params
def initialize file, options = {}, attachment = nil
super
@file = file
@params = options[:params]
@current_format = File.extname(@file.path)
@basename = File.basename(@file.path, @current_format)
end
def make
src = @file
dst = Tempfile.new([@basename.tableize, @format ? ".swf" : ''])
begin
parameters = []
parameters << @params
parameters << ":source"
parameters << ":dest"
parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
success = Paperclip.run("pdf2swf", parameters, :source => "#{File.expand_path(src.path)}",:dest => File.expand_path(dst.path))
rescue PaperclipCommandLineError => e
raise PaperclipError, "There was an error converting #{@basename} to swf"
end
dst
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment