sharp_office_bruce 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +17 -0
  2. data/.rspec +1 -0
  3. data/.travis.yml +14 -0
  4. data/Gemfile +4 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +76 -0
  7. data/Rakefile +8 -0
  8. data/ext/jodconverter-core-3.0-SNAPSHOT.jar +0 -0
  9. data/ext/sigar/libsigar-amd64-freebsd-6.so +0 -0
  10. data/ext/sigar/libsigar-amd64-linux.so +0 -0
  11. data/ext/sigar/libsigar-amd64-solaris.so +0 -0
  12. data/ext/sigar/libsigar-ia64-hpux-11.sl +0 -0
  13. data/ext/sigar/libsigar-ia64-linux.so +0 -0
  14. data/ext/sigar/libsigar-pa-hpux-11.sl +0 -0
  15. data/ext/sigar/libsigar-ppc-aix-5.so +0 -0
  16. data/ext/sigar/libsigar-ppc-linux.so +0 -0
  17. data/ext/sigar/libsigar-ppc64-aix-5.so +0 -0
  18. data/ext/sigar/libsigar-ppc64-linux.so +0 -0
  19. data/ext/sigar/libsigar-s390x-linux.so +0 -0
  20. data/ext/sigar/libsigar-sparc-solaris.so +0 -0
  21. data/ext/sigar/libsigar-sparc64-solaris.so +0 -0
  22. data/ext/sigar/libsigar-universal-macosx.dylib +0 -0
  23. data/ext/sigar/libsigar-universal64-macosx.dylib +0 -0
  24. data/ext/sigar/libsigar-x86-freebsd-5.so +0 -0
  25. data/ext/sigar/libsigar-x86-freebsd-6.so +0 -0
  26. data/ext/sigar/libsigar-x86-linux.so +0 -0
  27. data/ext/sigar/libsigar-x86-solaris.so +0 -0
  28. data/ext/sigar/sigar-amd64-winnt.dll +0 -0
  29. data/ext/sigar/sigar-x86-winnt.dll +0 -0
  30. data/ext/sigar/sigar-x86-winnt.lib +0 -0
  31. data/ext/sigar/sigar.jar +0 -0
  32. data/lib/sharp_office/office.rb +68 -0
  33. data/lib/sharp_office/version.rb +3 -0
  34. data/lib/sharp_office.rb +24 -0
  35. data/sharp_office.gemspec +23 -0
  36. data/spec/fixture/test.doc +0 -0
  37. data/spec/fixture/test.docx +0 -0
  38. data/spec/fixture/test.ppt +0 -0
  39. data/spec/fixture/test.xls +0 -0
  40. data/spec/sharp_office_spec.rb +39 -0
  41. data/spec/spec_helper.rb +15 -0
  42. metadata +133 -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/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ script: bundle exec rspec spec
7
+ before_install:
8
+ - sudo apt-get update
9
+ - sudo apt-get install imagemagick libmagickcore-dev
10
+ - sudo apt-get install -y ffmpeg libavcodec-extra-53 openoffice.org openoffice.org-writer unoconv ghostscript gsfonts ufraw graphicsmagick libgraphicsmagick1-dev libfreetype6-dev libjpeg-dev libgif-dev libtiff-dev libdjvulibre-dev libwmf-dev libmagickcore-dev libmagickwand-dev libpng-dev xpdf libexpat-dev gettext zlib1g-dev build-essential libfaac-dev libmp3lame0 libx264-dev libvpx-dev libtheora-dev libvorbis-dev gpac dcraw ufraw
11
+ - sudo apt-get clean
12
+ - wget http://www.swftools.org/swftools-0.9.1.tar.gz
13
+ - sh -c "tar xzvf swftools-0.9.1.tar.gz && cd swftools-0.9.1 && ./configure && make && sudo make install"
14
+
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,76 @@
1
+ ## SharpOffice
2
+
3
+ [![Build Status](https://travis-ci.org/SharpV/sharp_office.png?branch=master)](https://travis-ci.org/SharpV/sharp_office)
4
+
5
+ ## Requirements
6
+
7
+ ### Swftools
8
+
9
+ ```
10
+ #不建议使用这种方法
11
+ sudo add-apt-repository ppa:guilhem-fr/swftools
12
+ sudo apt-get update
13
+ sudo apt-get install swftools
14
+ ```
15
+ make it yourself
16
+ download: http://www.swftools.org/download.html
17
+ ```
18
+ tar -zvxf swftools-0.x.x.tar
19
+ cd swftools-0.x.x
20
+ ./configure
21
+ make
22
+ make install
23
+ ```
24
+ 可能会报错
25
+ ```
26
+ rm:无效选项 -- o
27
+ Try 'rm --help' for more information.
28
+ make[1]: *** [install] 错误 1
29
+ ```
30
+ 编辑 swfs/Makefile 和 swfs/Makefile.in两个文件
31
+ 找到 rm 命令,去掉后面的 -o -L 保存,再次install即可
32
+
33
+ ### LibreOffice https://wiki.ubuntu.com/LibreOffice
34
+
35
+ ``` 
36
+ sudo apt-get install python-software-properties
37
+ sudo apt-add-repository ppa:libreoffice/libreoffice-4-0
38
+ sudo apt-get install libreoffice
39
+ ```
40
+
41
+ ### ImageMagick
42
+
43
+ ```
44
+ sudo apt-get install imagemagick libmagickcore-dev gs
45
+ ```
46
+
47
+ ## Installation
48
+
49
+ Add this line to your application's Gemfile:
50
+
51
+ gem build sharp_office.gemspec
52
+
53
+ And then execute:
54
+
55
+ $ gem install ./sharp_office-1.0.1.gem
56
+
57
+ ## Usage
58
+
59
+ ``` ruby
60
+ require 'sharp_office'
61
+
62
+ SharpOffice.process('/Users/apple/Documents/test.doc')
63
+ => {: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"}
64
+
65
+ SharpOffice.process('/Users/apple/Documents/test.doc', {pages: '1-20'})
66
+ => {: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"}
67
+
68
+ ```
69
+
70
+ ## Contributing
71
+
72
+ 1. Fork it
73
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
74
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
75
+ 4. Push to the branch (`git push origin my-new-feature`)
76
+ 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,68 @@
1
+ require 'singleton'
2
+ require 'mini_magick'
3
+
4
+ module SharpOffice
5
+ class Office
6
+
7
+ attr_reader :path, :pdf_path, :swf_path
8
+ include Singleton
9
+
10
+ def start(path, options)
11
+ @path = File.expand_path(path)
12
+
13
+ system_or_exit(convert_to_pdf) unless options[:ignore_pdf]
14
+ system_or_exit(convert_to_swf) unless options[:ignore_swf]
15
+ system_or_exit(convert_to_cover) unless options[:ignore_cover]
16
+ image = MiniMagick::Image.open(cover_path)
17
+ image.resize "300x300"
18
+ image.write cover_path
19
+
20
+ #File.delete(tmp_file_path)
21
+
22
+ {:status => 'ok', :pdf_path => pdf_path, :swf_path => swf_path, :cover_path => cover_path}
23
+ end
24
+
25
+ protected
26
+
27
+ def convert_to_pdf
28
+ jar = File.expand_path File.join(File.dirname(__FILE__), "..", "..", "ext", "jodconverter-core-3.0-SNAPSHOT.jar")
29
+ sigar = File.expand_path File.join(File.dirname(__FILE__), "..", "..", "ext", "sigar")
30
+ "java -Djava.library.path=#{sigar} -jar #{jar} #{@path} #{pdf_path}"
31
+ end
32
+
33
+ def convert_to_swf
34
+ "pdf2swf #{pdf_path} #{swf_path}"
35
+ end
36
+
37
+ def convert_to_cover
38
+ "convert #{pdf_path}[0] #{cover_path}"
39
+ end
40
+
41
+ def pdf_path
42
+ if options[:ignore_pdf]
43
+ return @path if @path.end_with?('pdf')
44
+ end
45
+ @path.gsub('.', '-').to_s+'.pdf'
46
+
47
+ end
48
+
49
+ def cover_path
50
+ return '' if options[:ignore_cover]
51
+ @path.gsub('.', '-').to_s+'.png'
52
+ end
53
+
54
+ def swf_path
55
+ return '' if options[:ignore_swf]
56
+ @path.gsub('.', '-').to_s+'.swf'
57
+ end
58
+
59
+ private
60
+
61
+ def system_or_exit(cmd, stdout = nil)
62
+ puts "Executing #{cmd}"
63
+ cmd += " >#{stdout}" if stdout
64
+ system(cmd) or raise "******** Run failed ********"
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,3 @@
1
+ module SharpOffice
2
+ VERSION = "1.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, options={:pages => '1-20'})
20
+ raise Errno::ENOENT, "the file '#{path}' does not exist" unless File.exists?(path)
21
+ Office.instance.start(path, options)
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_bruce"
8
+ gem.version = SharpOffice::VERSION
9
+ gem.authors = ["heimirror"]
10
+ gem.email = ["heimirror@126.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/brucewu/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_dependency "mini_magick"
21
+ gem.add_development_dependency "rspec", "~> 2.13.0"
22
+
23
+ end
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,39 @@
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.should be_converted_successfully
16
+ end
17
+
18
+ it "should convert ppt successfully" do
19
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.ppt"))
20
+ @response.should be_converted_successfully
21
+
22
+ end
23
+
24
+ it "should convert xls successfully" do
25
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.xls"))
26
+ @response.should be_converted_successfully
27
+ end
28
+
29
+ it "should convert docx successfully" do
30
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.docx"))
31
+ @response.should be_converted_successfully
32
+ end
33
+
34
+ it "should convert docx with params successfully" do
35
+ @response = SharpOffice.process(File.expand_path("spec/fixture/test.docx"), {pages: '1-20'})
36
+ @response.should be_converted_successfully
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,15 @@
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
+
11
+ RSpec::Matchers.define :be_converted_successfully do
12
+ match do |conversion_response|
13
+ conversion_response[:status] == 'ok' && File.exist?(conversion_response[:pdf_path]) && File.exist?(conversion_response[:swf_path]) && File.exist?(conversion_response[:cover_path])
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sharp_office_bruce
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 1
7
+ - 0
8
+ - 1
9
+ version: 1.0.1
10
+ platform: ruby
11
+ authors:
12
+ - heimirror
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2014-11-17 00:00:00 +08:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mini_magick
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: rspec
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 2
41
+ - 13
42
+ - 0
43
+ version: 2.13.0
44
+ type: :development
45
+ version_requirements: *id002
46
+ description: Convert office document to pdf and swf
47
+ email:
48
+ - heimirror@126.com
49
+ executables: []
50
+
51
+ extensions: []
52
+
53
+ extra_rdoc_files: []
54
+
55
+ files:
56
+ - .gitignore
57
+ - .rspec
58
+ - .travis.yml
59
+ - Gemfile
60
+ - LICENSE.txt
61
+ - README.md
62
+ - Rakefile
63
+ - ext/jodconverter-core-3.0-SNAPSHOT.jar
64
+ - ext/sigar/libsigar-amd64-freebsd-6.so
65
+ - ext/sigar/libsigar-amd64-linux.so
66
+ - ext/sigar/libsigar-amd64-solaris.so
67
+ - ext/sigar/libsigar-ia64-hpux-11.sl
68
+ - ext/sigar/libsigar-ia64-linux.so
69
+ - ext/sigar/libsigar-pa-hpux-11.sl
70
+ - ext/sigar/libsigar-ppc-aix-5.so
71
+ - ext/sigar/libsigar-ppc-linux.so
72
+ - ext/sigar/libsigar-ppc64-aix-5.so
73
+ - ext/sigar/libsigar-ppc64-linux.so
74
+ - ext/sigar/libsigar-s390x-linux.so
75
+ - ext/sigar/libsigar-sparc-solaris.so
76
+ - ext/sigar/libsigar-sparc64-solaris.so
77
+ - ext/sigar/libsigar-universal-macosx.dylib
78
+ - ext/sigar/libsigar-universal64-macosx.dylib
79
+ - ext/sigar/libsigar-x86-freebsd-5.so
80
+ - ext/sigar/libsigar-x86-freebsd-6.so
81
+ - ext/sigar/libsigar-x86-linux.so
82
+ - ext/sigar/libsigar-x86-solaris.so
83
+ - ext/sigar/sigar-amd64-winnt.dll
84
+ - ext/sigar/sigar-x86-winnt.dll
85
+ - ext/sigar/sigar-x86-winnt.lib
86
+ - ext/sigar/sigar.jar
87
+ - lib/sharp_office.rb
88
+ - lib/sharp_office/office.rb
89
+ - lib/sharp_office/version.rb
90
+ - sharp_office.gemspec
91
+ - spec/fixture/test.doc
92
+ - spec/fixture/test.docx
93
+ - spec/fixture/test.ppt
94
+ - spec/fixture/test.xls
95
+ - spec/sharp_office_spec.rb
96
+ - spec/spec_helper.rb
97
+ has_rdoc: true
98
+ homepage: https://github.com/brucewu/sharp_office
99
+ licenses: []
100
+
101
+ post_install_message:
102
+ rdoc_options: []
103
+
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ segments:
111
+ - 0
112
+ version: "0"
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ requirements: []
121
+
122
+ rubyforge_project:
123
+ rubygems_version: 1.3.6
124
+ signing_key:
125
+ specification_version: 3
126
+ summary: Convert office document to pdf and swf
127
+ test_files:
128
+ - spec/fixture/test.doc
129
+ - spec/fixture/test.docx
130
+ - spec/fixture/test.ppt
131
+ - spec/fixture/test.xls
132
+ - spec/sharp_office_spec.rb
133
+ - spec/spec_helper.rb