Created
January 24, 2011 09:31
-
-
Save Krule/793003 to your computer and use it in GitHub Desktop.
Paperclip pdf2swf processor utilizing swftools
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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