sharp_office 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +43 -0
  5. data/Rakefile +8 -0
  6. data/ext/jodconverter-core-3.0-SNAPSHOT.jar +0 -0
  7. data/ext/sigar/libsigar-amd64-freebsd-6.so +0 -0
  8. data/ext/sigar/libsigar-amd64-linux.so +0 -0
  9. data/ext/sigar/libsigar-amd64-solaris.so +0 -0
  10. data/ext/sigar/libsigar-ia64-hpux-11.sl +0 -0
  11. data/ext/sigar/libsigar-ia64-linux.so +0 -0
  12. data/ext/sigar/libsigar-pa-hpux-11.sl +0 -0
  13. data/ext/sigar/libsigar-ppc-aix-5.so +0 -0
  14. data/ext/sigar/libsigar-ppc-linux.so +0 -0
  15. data/ext/sigar/libsigar-ppc64-aix-5.so +0 -0
  16. data/ext/sigar/libsigar-ppc64-linux.so +0 -0
  17. data/ext/sigar/libsigar-s390x-linux.so +0 -0
  18. data/ext/sigar/libsigar-sparc-solaris.so +0 -0
  19. data/ext/sigar/libsigar-sparc64-solaris.so +0 -0
  20. data/ext/sigar/libsigar-universal-macosx.dylib +0 -0
  21. data/ext/sigar/libsigar-universal64-macosx.dylib +0 -0
  22. data/ext/sigar/libsigar-x86-freebsd-5.so +0 -0
  23. data/ext/sigar/libsigar-x86-freebsd-6.so +0 -0
  24. data/ext/sigar/libsigar-x86-linux.so +0 -0
  25. data/ext/sigar/libsigar-x86-solaris.so +0 -0
  26. data/ext/sigar/sigar-amd64-winnt.dll +0 -0
  27. data/ext/sigar/sigar-x86-winnt.dll +0 -0
  28. data/ext/sigar/sigar-x86-winnt.lib +0 -0
  29. data/ext/sigar/sigar.jar +0 -0
  30. data/lib/sharp_office/office.rb +63 -0
  31. data/lib/sharp_office/version.rb +3 -0
  32. data/lib/sharp_office.rb +24 -0
  33. data/sharp_office.gemspec +23 -0
  34. data/spec/fixture/test.doc +0 -0
  35. data/spec/fixture/test.docx +0 -0
  36. data/spec/fixture/test.ppt +0 -0
  37. data/spec/fixture/test.xls +0 -0
  38. data/spec/sharp_office_spec.rb +45 -0
  39. data/spec/spec_helper.rb +10 -0
  40. metadata +138 -0
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in sharp_office.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 sharp
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # SharpOffice
2
+
3
+ Convert office document to pdf and swf
4
+
5
+ ## Requirements
6
+
7
+ ### Swftools
8
+
9
+ ### OpenOffice
10
+
11
+ ### ImageMagick
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ gem 'sharp_office'
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install sharp_office
26
+
27
+ ## Usage
28
+
29
+ ``` ruby
30
+ require 'rubygems'
31
+ require 'sharp_office'
32
+ SharpOffice.process('/Users/apple/Documents/test.doc')
33
+ => {:status=>"ok", :pdf_path=>"/Users/apple/Documents/test-doc.pdf", :swf_path=>"/Users/apple/Documents/test-doc.swf", :cover_path=>"/Users/apple/Documents/test-doc.png"}
34
+
35
+ ```
36
+
37
+ ## Contributing
38
+
39
+ 1. Fork it
40
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
41
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
42
+ 4. Push to the branch (`git push origin my-new-feature`)
43
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ # If you want to make this the default task
8
+ task :default => :spec
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,63 @@
1
+ require 'singleton'
2
+ require 'flash_tool'
3
+ require 'mini_magick'
4
+
5
+ module SharpOffice
6
+ class Office
7
+
8
+ attr_reader :path, :pdf_path, :swf_path
9
+ include Singleton
10
+
11
+ def start(path)
12
+ @path = File.expand_path(path)
13
+ system_or_exit convert_to_pdf
14
+ swfile = FlashTool::FlashObject.new(pdf_path)
15
+ swfile.save(swf_path)
16
+ system_or_exit "convert #{pdf_path} #{temp_file_path}"
17
+
18
+ image = MiniMagick::Image.open(temp_file_path)
19
+ image.resize "100x100"
20
+ image.write cover_path
21
+
22
+ File.delete(temp_file_path)
23
+
24
+ {status: 'ok', pdf_path: pdf_path, swf_path: swf_path, cover_path: cover_path}
25
+ end
26
+
27
+ def system_or_exit(cmd, stdout = nil)
28
+ puts "Executing #{cmd}"
29
+ cmd += " >#{stdout}" if stdout
30
+ system(cmd) or raise "******** Run failed ********"
31
+ end
32
+
33
+ protected
34
+
35
+ def convert_to_pdf
36
+ jar = File.expand_path File.join(File.dirname(__FILE__), "..", "..", "ext", "jodconverter-core-3.0-SNAPSHOT.jar")
37
+ sigar = File.expand_path File.join(File.dirname(__FILE__), "..", "..", "ext", "sigar")
38
+ "java -Djava.library.path=#{sigar} -jar #{jar} #{@path} #{pdf_path}"
39
+ end
40
+
41
+ def pdf_path
42
+ @path.gsub('.', '-').to_s+'.pdf'
43
+ end
44
+
45
+ def temp_file_path
46
+ @path.gsub('.', '-').to_s+'.temp'
47
+ end
48
+
49
+ def cover_path
50
+ @path.gsub('.', '-').to_s+'.png'
51
+ end
52
+
53
+ def swf_path
54
+ @path.gsub('.', '-').to_s+'.swf'
55
+ end
56
+
57
+ def convert_to_swf
58
+ output[/test/] # Running a regexp on the string throws error if it's not UTF-8
59
+ rescue ArgumentError
60
+ output.force_encoding("ISO-8859-1")
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,3 @@
1
+ module SharpOffice
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH.unshift File.dirname(__FILE__)
2
+
3
+ require 'logger'
4
+ require File.join(File.dirname(__FILE__), "sharp_office/version")
5
+ require File.join(File.dirname(__FILE__), "sharp_office/office")
6
+
7
+ module SharpOffice
8
+ def self.logger=(log)
9
+ @logger = log
10
+ end
11
+
12
+ def self.logger
13
+ return @logger if @logger
14
+ logger = Logger.new(STDOUT)
15
+ logger.level = Logger::INFO
16
+ @logger = logger
17
+ end
18
+
19
+ def self.process(path)
20
+ raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exists?(path)
21
+ Office.instance.start(path)
22
+ end
23
+
24
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sharp_office/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "sharp_office"
8
+ gem.version = SharpOffice::VERSION
9
+ gem.authors = ["sharp"]
10
+ gem.email = ["liu19850701@gmail.com"]
11
+ gem.description = %q{Convert office document to pdf and swf}
12
+ gem.summary = %q{Convert office document to pdf and swf}
13
+ gem.homepage = "https://github.com/SharpV/sharp_office"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency "rspec", "~> 2.13.0"
21
+ gem.add_development_dependency "mini_magick"
22
+ gem.add_development_dependency "flash_tool"
23
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+ require 'find'
3
+
4
+ describe SharpOffice do
5
+ context "given office files, and can be converted" do
6
+ after(:all) do
7
+ Find.find(File.expand_path("spec/fixture/")) do |path|
8
+ File.delete(path) if path =~ /.*\.pdf$/
9
+ File.delete(path) if path =~ /.*\.swf$/
10
+ File.delete(path) if path =~ /.*\.png$/
11
+ end
12
+ end
13
+ it "should convert doc successfully" do
14
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.doc"))
15
+ @response[:status].should == 'ok'
16
+ File.exist?(@response[:pdf_path]).should be_true
17
+ File.exist?(@response[:swf_path]).should be_true
18
+ File.exist?(@response[:cover_path]).should be_true
19
+ end
20
+
21
+ it "should convert ppt successfully" do
22
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.ppt"))
23
+ @response[:status].should == 'ok'
24
+ File.exist?(@response[:pdf_path]).should be_true
25
+ File.exist?(@response[:swf_path]).should be_true
26
+ File.exist?(@response[:cover_path]).should be_true
27
+ end
28
+
29
+ it "should convert xls successfully" do
30
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.xls"))
31
+ @response[:status].should == 'ok'
32
+ File.exist?(@response[:pdf_path]).should be_true
33
+ File.exist?(@response[:swf_path]).should be_true
34
+ File.exist?(@response[:cover_path]).should be_true
35
+ end
36
+
37
+ it "should convert docx successfully" do
38
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.docx"))
39
+ @response[:status].should == 'ok'
40
+ File.exist?(@response[:pdf_path]).should be_true
41
+ File.exist?(@response[:swf_path]).should be_true
42
+ File.exist?(@response[:cover_path]).should be_true
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ Bundler.require
4
+
5
+
6
+ RSpec.configure do |config|
7
+ config.filter_run focus: true
8
+ config.run_all_when_everything_filtered = true
9
+ end
10
+
metadata ADDED
@@ -0,0 +1,138 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sharp_office
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - sharp
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.13.0
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 2.13.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: mini_magick
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: flash_tool
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Convert office document to pdf and swf
63
+ email:
64
+ - liu19850701@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE.txt
72
+ - README.md
73
+ - Rakefile
74
+ - ext/jodconverter-core-3.0-SNAPSHOT.jar
75
+ - ext/sigar/libsigar-amd64-freebsd-6.so
76
+ - ext/sigar/libsigar-amd64-linux.so
77
+ - ext/sigar/libsigar-amd64-solaris.so
78
+ - ext/sigar/libsigar-ia64-hpux-11.sl
79
+ - ext/sigar/libsigar-ia64-linux.so
80
+ - ext/sigar/libsigar-pa-hpux-11.sl
81
+ - ext/sigar/libsigar-ppc-aix-5.so
82
+ - ext/sigar/libsigar-ppc-linux.so
83
+ - ext/sigar/libsigar-ppc64-aix-5.so
84
+ - ext/sigar/libsigar-ppc64-linux.so
85
+ - ext/sigar/libsigar-s390x-linux.so
86
+ - ext/sigar/libsigar-sparc-solaris.so
87
+ - ext/sigar/libsigar-sparc64-solaris.so
88
+ - ext/sigar/libsigar-universal-macosx.dylib
89
+ - ext/sigar/libsigar-universal64-macosx.dylib
90
+ - ext/sigar/libsigar-x86-freebsd-5.so
91
+ - ext/sigar/libsigar-x86-freebsd-6.so
92
+ - ext/sigar/libsigar-x86-linux.so
93
+ - ext/sigar/libsigar-x86-solaris.so
94
+ - ext/sigar/sigar-amd64-winnt.dll
95
+ - ext/sigar/sigar-x86-winnt.dll
96
+ - ext/sigar/sigar-x86-winnt.lib
97
+ - ext/sigar/sigar.jar
98
+ - lib/sharp_office.rb
99
+ - lib/sharp_office/office.rb
100
+ - lib/sharp_office/version.rb
101
+ - sharp_office.gemspec
102
+ - spec/fixture/test.doc
103
+ - spec/fixture/test.docx
104
+ - spec/fixture/test.ppt
105
+ - spec/fixture/test.xls
106
+ - spec/sharp_office_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: https://github.com/SharpV/sharp_office
109
+ licenses: []
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ! '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 1.8.24
129
+ signing_key:
130
+ specification_version: 3
131
+ summary: Convert office document to pdf and swf
132
+ test_files:
133
+ - spec/fixture/test.doc
134
+ - spec/fixture/test.docx
135
+ - spec/fixture/test.ppt
136
+ - spec/fixture/test.xls
137
+ - spec/sharp_office_spec.rb
138
+ - spec/spec_helper.rb