doc_2_pdf 1.0.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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +1 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +49 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/doc_2_pdf.gemspec +25 -0
- data/lib/doc_2_pdf/doc_pdf.rb +21 -0
- data/lib/doc_2_pdf/version.rb +3 -0
- data/lib/doc_2_pdf.rb +3 -0
- metadata +114 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e67924d06f3cf9ff055c926783440f3e38b61d94
|
4
|
+
data.tar.gz: 8b800fae1d3c4575cdaffa270f3f746ada4a5d27
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dcde060e8b8bd7e5a7d85b617a1fb67a2766c6d8a18f87aff1878960c6d56e6fcf43114e352e33439ea5df1ba23da5ea69dd132776db7ce4e2ee70701083dac
|
7
|
+
data.tar.gz: 9beceea911bdfb71b5cb31577b99deb75688a29e631c97748954b62bd797c9f7061b2a6c643815f8c8e2ce997a4fd480911a139362989b0242ffe892965869e1
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Sean Huber
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
doc_2_pdf
|
2
|
+
==============
|
3
|
+
|
4
|
+
`doc_2_pdf` converts a folder structure containing `.doc`/`.docx` files into a folder structure of .pdf files
|
5
|
+
|
6
|
+
|
7
|
+
Requirements and Dependencies
|
8
|
+
-----------------------------
|
9
|
+
|
10
|
+
Developed/Tested with Ruby version 2.3, but it should work with any version >= 1.9. `.doc`/`.docx` are converted to `.pdf` through the `libreconv` gem which depends on Libre Office.
|
11
|
+
|
12
|
+
|
13
|
+
Installation
|
14
|
+
-----------------------------
|
15
|
+
|
16
|
+
Add to your `Gemfile`:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'doc_2_pdf', '~> 1.0'
|
20
|
+
```
|
21
|
+
|
22
|
+
|
23
|
+
Usage
|
24
|
+
-----------------------------
|
25
|
+
|
26
|
+
First, configure `DocPdf`:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
DocPdf.configure(
|
30
|
+
doc_dir: '/some/path/with/doc/files', # required
|
31
|
+
pdf_dir: '/where/to/save/pdf/files' # required
|
32
|
+
)
|
33
|
+
```
|
34
|
+
|
35
|
+
To generate all docs in `doc_dir`, execute `.convert!`:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
DocPdf.convert! do |pdf_path|
|
39
|
+
puts "Created pdf file: #{pdf_path}"
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
`convert!` optionally accepts a code block with one argument. This argument (`pdf_path` in the above example) will be a string representing the path of the newly created pdf relative to `pdf_dif` defined at configuration. The folder structure `pdf_dir` will be identical to that of `doc_dir` but for every `.doc`/`.dox` file there will instead be a `.pdf` file with the same name.
|
44
|
+
|
45
|
+
|
46
|
+
License
|
47
|
+
-----------------------------
|
48
|
+
|
49
|
+
MIT-LICENSE.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "doc_2_pdf"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/doc_2_pdf.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'doc_2_pdf/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'doc_2_pdf'
|
8
|
+
spec.version = Doc2Pdf::VERSION
|
9
|
+
spec.authors = ['Sean Huber']
|
10
|
+
spec.email = ['seanhuber@seanhuber.com']
|
11
|
+
spec.summary = 'Converts a folder structure containing .doc/.docx files into a folder structure of .pdf files'
|
12
|
+
spec.homepage = 'https://github.com/seanhuber/doc_2_pdf'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = 'exe'
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ['lib']
|
19
|
+
|
20
|
+
spec.add_dependency 'libreconv'
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.12'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class DocPdf
|
2
|
+
def self.configure **opts
|
3
|
+
[:doc_dir, :pdf_dir].each do |required_opt|
|
4
|
+
raise ArgumentError, "Missing required config option: :#{required_opt}" unless opts[required_opt]
|
5
|
+
end
|
6
|
+
@@doc_dir = File.join(opts[:doc_dir], '') # adds trailing '/' if it doesn't already have one
|
7
|
+
@@pdf_dir = File.join(opts[:pdf_dir], '') # adds trailing '/' if it doesn't already have one
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.convert!
|
11
|
+
Dir.glob(File.join(@@doc_dir, '**', '*.{doc,docx}')) do |doc|
|
12
|
+
pdf_filename = File.basename(doc, '.*')+'.pdf'
|
13
|
+
relative_path = File.dirname doc.gsub(@@doc_dir, '')
|
14
|
+
relative_pdf_path = relative_path == '.' ? pdf_filename : File.join(relative_path, pdf_filename)
|
15
|
+
pdf_path = File.join @@pdf_dir, relative_pdf_path
|
16
|
+
FileUtils.mkdir_p File.dirname(pdf_path)
|
17
|
+
Libreconv.convert doc, pdf_path
|
18
|
+
yield(relative_pdf_path) if block_given?
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/doc_2_pdf.rb
ADDED
metadata
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: doc_2_pdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sean Huber
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: libreconv
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- seanhuber@seanhuber.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/console
|
84
|
+
- bin/setup
|
85
|
+
- doc_2_pdf.gemspec
|
86
|
+
- lib/doc_2_pdf.rb
|
87
|
+
- lib/doc_2_pdf/doc_pdf.rb
|
88
|
+
- lib/doc_2_pdf/version.rb
|
89
|
+
homepage: https://github.com/seanhuber/doc_2_pdf
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.5.1
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Converts a folder structure containing .doc/.docx files into a folder structure
|
113
|
+
of .pdf files
|
114
|
+
test_files: []
|