pdf_to_swf-paperclip-processor 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in pdf_to_swf-paperclip-processor.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,120 @@
1
+ # Ruby on Rails 3 Paperclip pdf to swf Processor #
2
+
3
+ This gem is Paperclip processor, utilizing swftools in order to convert uploaded pdf to swf.
4
+
5
+ ## Requirements ##
6
+
7
+ * [Paperclip][0] ~> 2.3
8
+ * [Ruby on Rails][1] ~> 3
9
+ * [SwfTools][2]
10
+
11
+ ## Installation ##
12
+
13
+ This gem is written and tested on Ruby on Rails 3 only. However, I see no reason why it should not work on earlier versions, as long as Paperclip is functional.
14
+
15
+ In order to install it, add
16
+
17
+ gem 'pdf_to_swf-paperclip-processor'
18
+
19
+ to your Gemfile and run
20
+
21
+ bundle
22
+
23
+ in your console. Bundler should take care of all the rest.
24
+
25
+ ## SwfTools Instalation ##
26
+
27
+ Install [swftools][2] using your favorite package manager. On OS X, the easiest way to do it is by using [Homebrew][3].
28
+
29
+ brew install swftools
30
+
31
+ Various linux distributions should use similar methods with their respected package managers.
32
+
33
+ If you are using Windows, you are in luck (this time), swftools also has a Windows binary.
34
+
35
+ Otherwise, just install from the source.
36
+
37
+ ## Using Processor ##
38
+
39
+ Use it as you would any other Paperclip processor. In your model:
40
+
41
+ class Document < ActiveRecord::Base
42
+
43
+ has_attached_file :document,
44
+
45
+ :styles => {
46
+ :original => { :params => "-z -j 100 -qq -G" }
47
+ },
48
+ :processors => [:pdf_to_swf]
49
+
50
+ end
51
+
52
+
53
+ which will convert your pdf document into swf. However, pdf extension will be retained.
54
+
55
+ In order to avoid this I have created a method to normalize file name and change it's extension.
56
+
57
+ class Document < ActiveRecord::Base
58
+
59
+ has_attached_file :document,
60
+ :styles => {
61
+ :original => { :params => "-z -j 100 -qq -G" }
62
+ },
63
+ :processors => [:pdf_to_swf],
64
+ :path => ":rails_root/public/system/:attachment/:normalized_file_name",
65
+ :url => "/system/:attachment/:normalized_file_name"
66
+
67
+ Paperclip.interpolates :normalized_file_name do |attachment, style|
68
+ attachment.instance.normalized_file_name
69
+ end
70
+
71
+ def normalized_file_name
72
+ file = self.document_file_name.gsub( /[^a-zA-Z0-9_\-\.]/, '_')
73
+ file = "#{self.id}-#{File.basename(file, ".pdf")}".slice(0...32)
74
+ "#{file}.swf".downcase
75
+ end
76
+ end
77
+
78
+ However, if you think you can do better, feel free to fork.
79
+
80
+ ### Params ###
81
+
82
+ Params have not been extrapolated and are passed directly to pdf2swf application. Documentation for those can be found on [swftools wiki][5].
83
+
84
+ -h , --help Print short help message and exit
85
+ -V , --version Print version info and exit
86
+ -o , --output file.swf Direct output to file.swf. If file.swf contains '%' (file%.swf), then each page goes to a seperate file.
87
+ -p , --pages range Convert only pages in range with range e.g. 1-20 or 1,4,6,9-11 or
88
+ -P , --password password Use password for deciphering the pdf.
89
+ -v , --verbose Be verbose. Use more than one -v for greater effect.
90
+ -z , --zlib Use Flash 6 (MX) zlib compression.
91
+ -i , --ignore Allows pdf2swf to change the draw order of the pdf. This may make the generated
92
+ -j , --jpegquality quality Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)
93
+ -s , --set param=value Set a SWF encoder specific parameter. See pdf2swf -s help for more information.
94
+ -w , --samewindow When converting pdf hyperlinks, don't make the links open a new window.
95
+ -t , --stop Insert a stop() command in each page.
96
+ -T , --flashversion num Set Flash Version in the SWF header to num.
97
+ -F , --fontdir directory Add directory to the font search path.
98
+ -b , --defaultviewer Link a standard viewer to the swf file.
99
+ -l , --defaultloader Link a standard preloader to the swf file which will be displayed while the main swf is loading.
100
+ -B , --viewer filename Link viewer filename to the swf file.
101
+ -L , --preloader filename Link preloader filename to the swf file.
102
+ -q , --quiet Suppress normal messages. Use -qq to suppress warnings, also.
103
+ -S , --shapes Don't use SWF Fonts, but store everything as shape.
104
+ -f , --fonts Store full fonts in SWF. (Don't reduce to used characters).
105
+ -G , --flatten Remove as many clip layers from file as possible.
106
+ -I , --info Don't do actual conversion, just display a list of all pages in the PDF.
107
+ -Q , --maxtime n Abort conversion after n seconds. Only available on Unix.
108
+
109
+ ## Release info ##
110
+
111
+ Be warned, this gem is released as early alpha version and if you are using it you are doing so on your own responsibility.
112
+
113
+ Have fun with it and drop me a note if you like it.
114
+
115
+
116
+ [0]: https://github.com/thoughtbot/paperclip
117
+ [1]: http://rubyonrails.org/
118
+ [2]: http://www.swftools.org/
119
+ [3]: http://mxcl.github.com/homebrew/
120
+ [5]: http://wiki.swftools.org/index.php/Pdf2swf
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,34 @@
1
+ require "paperclip"
2
+ module Paperclip
3
+ class PdfToSwf < Processor
4
+
5
+ attr_accessor :params
6
+
7
+ def initialize file, options = {}, attachment = nil
8
+ super
9
+ @file = file
10
+ @params = options[:params]
11
+ @current_format = File.extname(@file.path)
12
+ @basename = File.basename(@file.path, @current_format)
13
+ end
14
+
15
+ def make
16
+ src = @file
17
+ dst = Tempfile.new([@basename.tableize])
18
+ begin
19
+ parameters = []
20
+ parameters << @params
21
+ parameters << ":source"
22
+ parameters << ":dest"
23
+
24
+ parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
25
+
26
+ success = Paperclip.run("pdf2swf", parameters, :source => "#{File.expand_path(src.path)}",:dest => File.expand_path(dst.path))
27
+ rescue PaperclipCommandLineError => e
28
+ raise PaperclipError, "There was an error converting #{@basename} to swf"
29
+ end
30
+ dst
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,7 @@
1
+ module Pdftoswf
2
+ module Paperclip
3
+ module Processor
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "pdf_to_swf-paperclip-processor/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "pdf_to_swf-paperclip-processor"
7
+ s.version = Pdftoswf::Paperclip::Processor::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Armin Pašalić"]
10
+ s.email = ["apasalic@devlogic.eu"]
11
+ s.homepage = "https://github.com/Krule/pdf_to_swf-paperclip-processor"
12
+ s.summary = %q{Converts uploaded pdf to swf}
13
+ s.description = %q{This gem is simple Paperclip processor which uses swftools to convert uploaded pdf files to swf}
14
+
15
+ s.rubyforge_project = "pdf_to_swf-paperclip-processor"
16
+
17
+ s.add_dependency "rails", "~> 3.0"
18
+ s.add_dependency "paperclip", "~> 2.3"
19
+
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
22
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
23
+ s.require_paths = ["lib"]
24
+ end
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pdf_to_swf-paperclip-processor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - "Armin Pa\xC5\xA1ali\xC4\x87"
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-01-24 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: rails
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 3
32
+ - 0
33
+ version: "3.0"
34
+ type: :runtime
35
+ version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: paperclip
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 5
45
+ segments:
46
+ - 2
47
+ - 3
48
+ version: "2.3"
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: This gem is simple Paperclip processor which uses swftools to convert uploaded pdf files to swf
52
+ email:
53
+ - apasalic@devlogic.eu
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - .gitignore
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - lib/pdf_to_swf-paperclip-processor.rb
66
+ - lib/pdf_to_swf-paperclip-processor/version.rb
67
+ - pdf_to_swf-paperclip-processor.gemspec
68
+ has_rdoc: true
69
+ homepage: https://github.com/Krule/pdf_to_swf-paperclip-processor
70
+ licenses: []
71
+
72
+ post_install_message:
73
+ rdoc_options: []
74
+
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ hash: 3
83
+ segments:
84
+ - 0
85
+ version: "0"
86
+ required_rubygems_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ hash: 3
92
+ segments:
93
+ - 0
94
+ version: "0"
95
+ requirements: []
96
+
97
+ rubyforge_project: pdf_to_swf-paperclip-processor
98
+ rubygems_version: 1.4.1
99
+ signing_key:
100
+ specification_version: 3
101
+ summary: Converts uploaded pdf to swf
102
+ test_files: []
103
+