libreconv 0.6.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a009fa5b2db0723e30e82735267f0ba9e7e37d3a
4
- data.tar.gz: acef625a46cb3405d5a62e3f3e48d76f57ead885
3
+ metadata.gz: 3d7dc0c6cbb0739fa5b66291ca92f91cfd96851c
4
+ data.tar.gz: 736c8bbebcbe160492093410c98f3f2ccc2f596e
5
5
  SHA512:
6
- metadata.gz: eea9a950ba37821da056e71d5f4a0c279a6cb1892fad82391177b5b328611fe521e5de826406275f68d1e10706b6d9e7a4ffae7766b558dbd10c70c887a40b55
7
- data.tar.gz: b7d03a1eb8a4f2772656a7b3db4bf2fc5195ede5145eb34540794b4bec2f3bac1e4335ac3f685ef36dc048dcd8684e846a148cf3d7d576f7153a878c6f7f3cec
6
+ metadata.gz: 8eeed18bc37356b6f5b900468c181825c798d9c433275bd13e1a0c970d79d0afe48c4cc22d0e854ff4870b46905d0979f06c3cff8a0a4f47dc7efd3d2fa43c52
7
+ data.tar.gz: e9f7fe927979a2fb3409f7494e6f8f15421630fbbb718700aca6c6831055e6aa9ed4900d54b75afe1cb349c85340a6811cc2ae2cec65620a6a6db665949e79af
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ - rbx-19mode
6
+ notifications:
7
+ recipients:
8
+ - ricny046@gmail.com
9
+ before_install:
10
+ - sudo apt-get install libreoffice
data/README.md CHANGED
@@ -3,6 +3,7 @@
3
3
  Convert office documents to PDF using LibreOffice / OpenOffice.
4
4
 
5
5
  [![Code Climate](https://codeclimate.com/github/ricn/libreconv.png)](https://codeclimate.com/github/ricn/libreconv)
6
+ [![Build Status](https://travis-ci.org/ricn/libreconv.png?branch=master)](https://travis-ci.org/ricn/libreconv)
6
7
 
7
8
  ## Installation
8
9
 
@@ -25,12 +26,16 @@ You need to install Libreoffice or Openoffice on your system to use this gem. Th
25
26
  ```ruby
26
27
  require 'libreconv'
27
28
 
28
- # Converts document.docx to document.pdf
29
+ # Converts document.docx to my_document_as.pdf
30
+ # This requires that the soffice binary is present in your PATH.
31
+ Libreconv.convert('document.docx', '/Users/ricn/pdf_documents/my_document_as.pdf')
32
+
33
+ # Converts document.docx to pdf and writes the output to the specified path
29
34
  # This requires that the soffice binary is present in your PATH.
30
35
  Libreconv.convert('document.docx', '/Users/ricn/pdf_documents')
31
36
 
32
37
  # You can also convert a source file directly from an URL
33
- Libreconv.convert('http://myserver.com/123/document.docx', '/Users/ricn/pdf_documents')
38
+ Libreconv.convert('http://myserver.com/123/document.docx', '/Users/ricn/pdf_documents/doc.pdf')
34
39
 
35
40
  # Converts document.docx to document.pdf
36
41
  # If you for some reason can't have soffice in your PATH you can specifiy the file path to the soffice binary
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/doc.pdf ADDED
@@ -0,0 +1,79 @@
1
+ %PDF-1.4
2
+ %äüöß
3
+ 2 0 obj
4
+ <</Length 3 0 R/Filter/FlateDecode>>
5
+ stream
6
+ x��P; �0��+nZ��]!��nB�A�|l�]��^s�(H.��\�Z�]ݠ��+|m�u�na8�����.j��G����k
7
+ ՗}=�dXȧ����{o�%��(j�� ���+��n�3v�����\��g�H.��\|}�4����?
8
+ �䳴?C�=�Q�a�y����j e�i�
9
+ endstream
10
+ endobj
11
+
12
+ 3 0 obj
13
+ 216
14
+ endobj
15
+
16
+ 5 0 obj
17
+ <</Type/Font/Subtype/Type1/BaseFont/Helvetica
18
+ /Encoding/WinAnsiEncoding
19
+ >>
20
+ endobj
21
+
22
+ 6 0 obj
23
+ <</F1 5 0 R
24
+ >>
25
+ endobj
26
+
27
+ 7 0 obj
28
+ <</Font 6 0 R
29
+ /ProcSet[/PDF/Text]
30
+ >>
31
+ endobj
32
+
33
+ 1 0 obj
34
+ <</Type/Page/Parent 4 0 R/Resources 7 0 R/MediaBox[0 0 595 842]/Group<</S/Transparency/CS/DeviceRGB/I true>>/Contents 2 0 R>>
35
+ endobj
36
+
37
+ 4 0 obj
38
+ <</Type/Pages
39
+ /Resources 7 0 R
40
+ /MediaBox[ 0 0 595 842 ]
41
+ /Kids[ 1 0 R ]
42
+ /Count 1>>
43
+ endobj
44
+
45
+ 8 0 obj
46
+ <</Type/Catalog/Pages 4 0 R
47
+ /OpenAction[1 0 R /XYZ null null 0]
48
+ /Lang(en)
49
+ >>
50
+ endobj
51
+
52
+ 9 0 obj
53
+ <</Creator<FEFF005700720069007400650072>
54
+ /Producer<FEFF004C0069006200720065004F0066006600690063006500200034002E0030>
55
+ /CreationDate(D:20130413003036+02'00')>>
56
+ endobj
57
+
58
+ xref
59
+ 0 10
60
+ 0000000000 65535 f
61
+ 0000000501 00000 n
62
+ 0000000019 00000 n
63
+ 0000000306 00000 n
64
+ 0000000643 00000 n
65
+ 0000000326 00000 n
66
+ 0000000417 00000 n
67
+ 0000000448 00000 n
68
+ 0000000741 00000 n
69
+ 0000000834 00000 n
70
+ trailer
71
+ <</Size 10/Root 8 0 R
72
+ /Info 9 0 R
73
+ /ID [ <5B1DA112593D69DE853EB34CE2A8F361>
74
+ <5B1DA112593D69DE853EB34CE2A8F361> ]
75
+ /DocChecksum /4269040604A6FE91FF4EF9808079BD6D
76
+ >>
77
+ startxref
78
+ 1008
79
+ %%EOF
@@ -1,3 +1,3 @@
1
1
  module Libreconv
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/libreconv.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "libreconv/version"
2
2
  require "uri"
3
3
  require "net/http"
4
+ require "tmpdir"
4
5
 
5
6
  module Libreconv
6
7
 
@@ -11,9 +12,10 @@ module Libreconv
11
12
  class Converter
12
13
  attr_accessor :soffice_command
13
14
 
14
- def initialize(source, target_path, soffice_command = nil)
15
+ def initialize(source, target, soffice_command = nil)
15
16
  @source = source
16
- @target_path = target_path
17
+ @target = target
18
+ @target_path = Dir.tmpdir
17
19
  @soffice_command = soffice_command
18
20
  determine_soffice_command
19
21
  check_source_type
@@ -27,6 +29,8 @@ module Libreconv
27
29
  cmd = "#{@soffice_command} --headless --convert-to pdf #{@source} -outdir #{@target_path}"
28
30
  pid = Process.spawn(cmd, [:out, :err] => "/dev/null")
29
31
  Process.waitpid(pid)
32
+ target_tmp_file = "#{@target_path}/#{File.basename(@source, ".*")}.pdf"
33
+ FileUtils.cp target_tmp_file, @target
30
34
  end
31
35
 
32
36
  private
@@ -53,8 +57,7 @@ module Libreconv
53
57
  def check_source_type
54
58
  is_file = File.exists?(@source) && !File.directory?(@source)
55
59
  is_http = URI(@source).scheme == "http" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
56
- is_https = URI(@source).scheme == "https" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
57
-
60
+ is_https = URI(@source).scheme == "https" && Net::HTTP.get_response(URI(@source)).is_a?(Net::HTTPSuccess)
58
61
  raise IOError, "Source (#{@source}) is neither a file nor an URL." unless is_file || is_http || is_https
59
62
  end
60
63
  end
data/libreconv.gemspec CHANGED
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_development_dependency "bundler", "~> 1.3"
22
22
  spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
23
24
  end
@@ -1,6 +1,8 @@
1
1
  # encoding: utf-8
2
-
3
2
  require 'spec_helper'
3
+ require 'webrick'
4
+
5
+ include WEBrick
4
6
 
5
7
  describe Libreconv do
6
8
 
@@ -9,14 +11,29 @@ describe Libreconv do
9
11
  @doc_file = file_path("doc.doc")
10
12
  @pptx_file = file_path("pptx.pptx")
11
13
  @ppt_file = file_path("ppt.ppt")
12
- @bin_file = file_path("bin.bin")
13
14
  @target_path = "/tmp/libreconv"
15
+
16
+ dir = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
17
+ port = 50506
18
+ @url = "http://#{Socket.gethostname}:#{port}"
19
+ @t1 = Thread.new do
20
+ @server = HTTPServer.new(:Port => port, :DocumentRoot => dir, :AccessLog => [], :Logger => WEBrick::Log::new("/dev/null", 7))
21
+ @server.start
22
+ end
14
23
  end
15
24
 
16
- after(:all) do
25
+ before(:each) do
26
+ FileUtils.mkdir_p @target_path
27
+ end
28
+
29
+ after(:each) do
17
30
  FileUtils.rm_rf @target_path
18
31
  end
19
32
 
33
+ after(:all) do
34
+ @t1.exit
35
+ end
36
+
20
37
  describe Libreconv::Converter do
21
38
  describe "#new" do
22
39
  it "should raise error if soffice command does not exists" do
@@ -29,48 +46,47 @@ describe Libreconv do
29
46
  end
30
47
 
31
48
  describe "#convert" do
49
+ it "should convert a docx do pdf specifying target_file" do
50
+ target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
51
+ converter = Libreconv::Converter.new(@doc_file, target_file)
52
+ converter.convert
53
+ File.file?(target_file).should == true
54
+ end
55
+
32
56
  it "should convert a doc to pdf" do
33
57
  target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
34
58
  converter = Libreconv::Converter.new(@doc_file, @target_path)
35
59
  converter.convert
36
- File.exists?(target_file).should == true
60
+ File.file?(target_file).should == true
37
61
  end
38
62
 
39
63
  it "should convert a docx to pdf" do
40
64
  target_file = "#{@target_path}/#{File.basename(@docx_file, ".docx")}.pdf"
41
65
  converter = Libreconv::Converter.new(@docx_file, @target_path)
42
66
  converter.convert
43
- File.exists?(target_file).should == true
67
+ File.file?(target_file).should == true
44
68
  end
45
69
 
46
70
  it "should convert a pptx to pdf" do
47
71
  target_file = "#{@target_path}/#{File.basename(@pptx_file, ".pptx")}.pdf"
48
72
  converter = Libreconv::Converter.new(@pptx_file, @target_path)
49
73
  converter.convert
50
- File.exists?(target_file).should == true
74
+ File.file?(target_file).should == true
51
75
  end
52
76
 
53
77
  it "should convert a ppt to pdf" do
54
78
  target_file = "#{@target_path}/#{File.basename(@ppt_file, ".ppt")}.pdf"
55
79
  converter = Libreconv::Converter.new(@ppt_file, @target_path)
56
80
  converter.convert
57
- File.exists?(target_file).should == true
81
+ File.file?(target_file).should == true
58
82
  end
59
83
 
60
84
  it "should convert a docx to pdf specifying an URL as source" do
61
- url = "https://www.filepicker.io/api/file/XqCEPkH9RdOQr0S6zF5N"
62
- target_file = "#{@target_path}/XqCEPkH9RdOQr0S6zF5N.pdf"
85
+ url = "#{@url}/docx.docx"
86
+ target_file = "#{@target_path}/docx.pdf"
63
87
  converter = Libreconv::Converter.new(url, @target_path)
64
88
  converter.convert
65
- File.exists?(target_file).should == true
66
- end
67
-
68
- it "try converting binary file" do
69
- source = @bin_file
70
- target_file = "#{@target_path}/#{File.basename(source, ".bin")}.pdf"
71
- converter = Libreconv::Converter.new(source, @target_path)
72
- converter.convert
73
- File.exists?(target_file).should == false
89
+ File.file?(target_file).should == true
74
90
  end
75
91
  end
76
92
 
@@ -92,7 +108,7 @@ describe Libreconv do
92
108
  it "should convert a file to pdf" do
93
109
  target_file = "#{@target_path}/#{File.basename(@doc_file, ".doc")}.pdf"
94
110
  Libreconv.convert(@doc_file, @target_path)
95
- File.exists?(target_file).should == true
111
+ File.file?(target_file).should == true
96
112
  end
97
113
  end
98
114
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libreconv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Nyström
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-31 00:00:00.000000000 Z
11
+ date: 2013-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: ' Convert office documents to PDF using LibreOffice / OpenOffice for
42
56
  the heavy lifting. '
43
57
  email:
@@ -48,14 +62,15 @@ extra_rdoc_files: []
48
62
  files:
49
63
  - .gitignore
50
64
  - .rspec
65
+ - .travis.yml
51
66
  - Gemfile
52
67
  - LICENSE.txt
53
68
  - README.md
54
69
  - Rakefile
70
+ - doc.pdf
55
71
  - lib/libreconv.rb
56
72
  - lib/libreconv/version.rb
57
73
  - libreconv.gemspec
58
- - spec/fixtures/bin.bin
59
74
  - spec/fixtures/doc.doc
60
75
  - spec/fixtures/docx.docx
61
76
  - spec/fixtures/ppt.ppt
@@ -88,7 +103,6 @@ signing_key:
88
103
  specification_version: 4
89
104
  summary: Convert office documents to PDF.
90
105
  test_files:
91
- - spec/fixtures/bin.bin
92
106
  - spec/fixtures/doc.doc
93
107
  - spec/fixtures/docx.docx
94
108
  - spec/fixtures/ppt.ppt
Binary file