doc_2_pdf 1.0.0 → 1.1.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 +4 -4
- data/README.md +15 -0
- data/lib/doc_2_pdf/doc_pdf.rb +22 -6
- data/lib/doc_2_pdf/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae84925d905241ade8b9027c7cb934ec14c9bbf5
|
4
|
+
data.tar.gz: ba81fd65e1f75cc1791cfed854a4ae16c3326031
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a3d2f8d2619a71733b06187595523b50cef32d21a6a90f79d9916724833559891a799e0d92720890ac9a4dd77874183a14fab51ea4966db68c84c8c295176cb
|
7
|
+
data.tar.gz: e50e0624a50a5a40c9901ce542c7520c0e8fec5048ecd635ba8ae4b5260b0a88ab01de8b2076591b019a1c8ab7764c189e52c59a1d774630bbfa982ea5274f85
|
data/README.md
CHANGED
@@ -43,6 +43,21 @@ end
|
|
43
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
44
|
|
45
45
|
|
46
|
+
Alternatively a single doc file can be converted to pdf using the `convert_single!` method:
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
doc_dir = '/some/path/with/doc/files'
|
50
|
+
pdf_dir = '/where/to/save/pdf/files'
|
51
|
+
|
52
|
+
DocPdf.configure doc_dir: doc_dir, pdf_dir: pdf_dir
|
53
|
+
|
54
|
+
relative_pdf_path = DocPdf.convert_single! File.join(doc_dir, 'My Word Doc.doc')
|
55
|
+
|
56
|
+
puts File.join pdf_dir, relative_pdf_path
|
57
|
+
# => '/where/to/save/pdf/files/My Word Doc.doc/'
|
58
|
+
```
|
59
|
+
|
60
|
+
|
46
61
|
License
|
47
62
|
-----------------------------
|
48
63
|
|
data/lib/doc_2_pdf/doc_pdf.rb
CHANGED
@@ -9,13 +9,29 @@ class DocPdf
|
|
9
9
|
|
10
10
|
def self.convert!
|
11
11
|
Dir.glob(File.join(@@doc_dir, '**', '*.{doc,docx}')) do |doc|
|
12
|
-
|
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
|
12
|
+
relative_pdf_path = convert_doc doc
|
18
13
|
yield(relative_pdf_path) if block_given?
|
19
14
|
end
|
20
15
|
end
|
16
|
+
|
17
|
+
def self.convert_single! doc
|
18
|
+
convert_doc doc
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.doc? file_path
|
22
|
+
['.doc', '.docx'].include? File.extname(file_path)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.convert_doc doc
|
28
|
+
raise ArgumentError, "Not a .doc/.docx file: #{doc}" unless doc?(doc)
|
29
|
+
pdf_filename = File.basename(doc, '.*')+'.pdf'
|
30
|
+
relative_path = File.dirname doc.gsub(@@doc_dir, '')
|
31
|
+
relative_pdf_path = relative_path == '.' ? pdf_filename : File.join(relative_path, pdf_filename)
|
32
|
+
pdf_path = File.join @@pdf_dir, relative_pdf_path
|
33
|
+
FileUtils.mkdir_p File.dirname(pdf_path)
|
34
|
+
Libreconv.convert doc, pdf_path
|
35
|
+
relative_pdf_path
|
36
|
+
end
|
21
37
|
end
|
data/lib/doc_2_pdf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: doc_2_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean Huber
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: libreconv
|