html2pdf 0.0.6 → 0.0.7
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/.gitignore +0 -1
- data/CHANGELOGS.md +5 -0
- data/README.md +14 -16
- data/html2pdf.gemspec +5 -5
- data/lib/html2pdf.rb +1 -1
- data/lib/html2pdf/cli.rb +2 -11
- data/lib/html2pdf/html2pdf.rb +49 -0
- data/lib/html2pdf/version.rb +1 -1
- data/rubocop-todo.yml +11 -56
- data/test/fixtures/samples/demo1_xxx.rb +3 -3
- data/test/fixtures/samples/demo2_xxx.rb +4 -4
- data/test/lib/html2pdf/test_html2pdf.rb +14 -0
- metadata +20 -20
- data/lib/html2pdf/utils.rb +0 -51
- data/test/lib/html2pdf/test_utils.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a66264ef9c9544f757a96c15ab564a7d5cd43382
|
4
|
+
data.tar.gz: e1544c387847a14833443310b54196b5bf5336cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: db1950e020e7f3586b2b58f9d64d654c716b2f7c2accb80a4d9fc1c0d66c352fb6f3104e22add52dd056d60a0c04c9cfe38ba6710eba4311b6a2b76c140224d0
|
7
|
+
data.tar.gz: 2e7f43e76cf9205875c4c35906fd8da47b44d75a07e4f4dcd001b107cf9d083e07680a404556958093088ec42d6368d0d871f8dbbe1895ae9ad2bab46c9ee309
|
data/.gitignore
CHANGED
data/CHANGELOGS.md
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,20 @@
|
|
1
1
|
## Html2Pdf
|
2
2
|
|
3
|
-
[]
|
4
|
-
[]
|
5
|
-
[]
|
6
|
-
[](https://coderwall.com/agilecreativity)
|
3
|
+
[][gem]
|
4
|
+
[][gemnasium]
|
5
|
+
[][codeclimate]
|
7
6
|
|
8
|
-
|
7
|
+
[gemnasium]: https://gemnasium.com/agilecreativity/html2pdf
|
8
|
+
[codeclimate]: https://codeclimate.com/github/agilecreativity/html2pdf
|
9
|
+
[gem]: http://badge.fury.io/rb/html2pdf
|
10
|
+
|
11
|
+
Convert multiple html or xhtml files to pdfs using the power of [wkhtmltopdf][].
|
9
12
|
|
10
13
|
### Installation
|
11
14
|
|
12
15
|
### Mandatory Requirement
|
13
16
|
|
14
|
-
- [
|
17
|
+
- [wkhtmltopdf][] - please see [wkhtmltopdf installation][] for detail
|
15
18
|
|
16
19
|
### Dependencies
|
17
20
|
|
@@ -39,10 +42,6 @@ html2pdf export [OPTIONS]
|
|
39
42
|
Options:
|
40
43
|
-b, [--base-dir=BASE_DIR] # Base directory
|
41
44
|
# Default: . (current directory)
|
42
|
-
-n, [--inc-words=one two three] # List of words to be included in the result
|
43
|
-
-x, [--exc-words=one two three] # List of words to be excluded from the result
|
44
|
-
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
45
|
-
# Default: true
|
46
45
|
-r, [--recursive], [--no-recursive] # Search for files recursively
|
47
46
|
# Default: true
|
48
47
|
-v, [--version], [--no-version] # Display version information
|
@@ -53,7 +52,7 @@ Options:
|
|
53
52
|
- Convert all `xhtml` and `html` from `test/fixtures/samples` directory
|
54
53
|
recursively
|
55
54
|
```
|
56
|
-
html2pdf -b test/fixtures/samples -r
|
55
|
+
html2pdf export -b test/fixtures/samples -r
|
57
56
|
```
|
58
57
|
Before the run
|
59
58
|
```
|
@@ -92,15 +91,14 @@ the pdf version of it.
|
|
92
91
|
|
93
92
|
### Contributing
|
94
93
|
|
95
|
-
1. Fork it ( http://github.com
|
94
|
+
1. Fork it ( http://github.com/agilecreativity/html2pdf/fork )
|
96
95
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
97
96
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
98
97
|
4. Push to the branch (`git push origin my-new-feature`)
|
99
98
|
5. Create new Pull Request
|
100
99
|
|
101
|
-
[Wkhtmltopdf]: http://wkhtmltopdf.org/
|
102
100
|
[vim_printer]: https://github.com/agilecreativity/vim_printer
|
103
101
|
[pdfs2pdf]: https://github.com/agilecreativity/pdfs2pdf
|
104
|
-
[
|
105
|
-
[
|
106
|
-
|
102
|
+
[wkhtmltopdf]: http://wkhtmltopdf.org/
|
103
|
+
[wkhtmltopdf installation]: https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF
|
104
|
+
|
data/html2pdf.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Html2Pdf::VERSION
|
9
9
|
spec.authors = ['Burin Choomnuan']
|
10
10
|
spec.email = ['agilecreativity@gmail.com']
|
11
|
-
spec.summary = %q(
|
12
|
-
spec.description = %q(Export html or xhtml
|
11
|
+
spec.summary = %q(Bulk export list of html or xhtml files to pdfs with 'wkhtmltopdf')
|
12
|
+
spec.description = %q(Export list of html or xhtml files to pdfs with 'wkhtmltopdf')
|
13
13
|
spec.homepage = 'https://github.com/agilecreativity/html2pdf'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
spec.files = Dir.glob('{bin,lib}/**/*') + %w(Gemfile
|
@@ -23,10 +23,10 @@ Gem::Specification.new do |spec|
|
|
23
23
|
rubocop-todo.yml)
|
24
24
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
25
25
|
spec.test_files = Dir.glob('{test}/**/*')
|
26
|
-
spec.require_paths = [
|
27
|
-
spec.add_runtime_dependency 'thor'
|
26
|
+
spec.require_paths = ['lib']
|
27
|
+
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
28
28
|
spec.add_runtime_dependency 'agile_utils', '~> 0.0.9'
|
29
|
-
spec.add_runtime_dependency 'code_lister', '~> 0.0.
|
29
|
+
spec.add_runtime_dependency 'code_lister', '~> 0.0.9'
|
30
30
|
spec.add_development_dependency 'awesome_print', '~> 1.2'
|
31
31
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
32
32
|
spec.add_development_dependency 'gem-ctags', '~> 1.0'
|
data/lib/html2pdf.rb
CHANGED
data/lib/html2pdf/cli.rb
CHANGED
@@ -5,18 +5,13 @@ require_relative '../html2pdf'
|
|
5
5
|
module Html2Pdf
|
6
6
|
class CLI < Thor
|
7
7
|
desc 'export', 'export multiple html files to pdfs'
|
8
|
-
|
9
8
|
method_option *AgileUtils::Options::BASE_DIR
|
10
|
-
method_option *AgileUtils::Options::INC_WORDS
|
11
|
-
method_option *AgileUtils::Options::EXC_WORDS
|
12
|
-
method_option *AgileUtils::Options::IGNORE_CASE
|
13
9
|
method_option *AgileUtils::Options::RECURSIVE
|
14
10
|
method_option *AgileUtils::Options::VERSION
|
15
|
-
|
16
11
|
def export
|
17
12
|
opts = options.symbolize_keys
|
18
13
|
|
19
|
-
unless Html2Pdf
|
14
|
+
unless Html2Pdf.softwares_installed?
|
20
15
|
fail 'You must have valid `wkhtmltopdf` and `ghostscript` installation'
|
21
16
|
end
|
22
17
|
|
@@ -29,7 +24,7 @@ module Html2Pdf
|
|
29
24
|
exts: %w(html xhtml),
|
30
25
|
recursive: true
|
31
26
|
elapsed = AgileUtils::FileUtil.time do
|
32
|
-
Html2Pdf
|
27
|
+
Html2Pdf.to_pdfs(input_files)
|
33
28
|
end
|
34
29
|
|
35
30
|
generated_files = AgileUtils::FileUtil.add_suffix(input_files, 'pdf')
|
@@ -49,10 +44,6 @@ Usage:
|
|
49
44
|
Options:
|
50
45
|
-b, [--base-dir=BASE_DIR] # Base directory
|
51
46
|
# Default: . (current directory)
|
52
|
-
-n, [--inc-words=one two three] # List of words to be included in the result
|
53
|
-
-x, [--exc-words=one two three] # List of words to be excluded from the result
|
54
|
-
-i, [--ignore-case], [--no-ignore-case] # Match case insensitively
|
55
|
-
# Default: true
|
56
47
|
-r, [--recursive], [--no-recursive] # Search for files recursively
|
57
48
|
# Default: true
|
58
49
|
-v, [--version], [--no-version] # Display version information
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'open3'
|
2
|
+
require 'fileutils'
|
3
|
+
require_relative '../html2pdf'
|
4
|
+
|
5
|
+
module Html2Pdf
|
6
|
+
class << self
|
7
|
+
# Batch convert to pdf using `wkhtmltopdf` tool
|
8
|
+
#
|
9
|
+
# @param [Array<String>] files the input file list
|
10
|
+
# @param [String] base_dir the base directory
|
11
|
+
def to_pdfs(files)
|
12
|
+
files.each_with_index do |file, index|
|
13
|
+
puts "Convert file #{index + 1} of #{files.size} : #{file}"
|
14
|
+
to_pdf(file)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convert '*.xhtml' or '*.html' to pdf
|
19
|
+
#
|
20
|
+
# @param filename input filename
|
21
|
+
def to_pdf(filename)
|
22
|
+
fail "Invalid input file #{filename}" unless File.exist?(filename)
|
23
|
+
command = [
|
24
|
+
'wkhtmltopdf',
|
25
|
+
'--margin-top 4',
|
26
|
+
'--margin-bottom 4',
|
27
|
+
'--margin-left 4',
|
28
|
+
'--margin-right 4',
|
29
|
+
'--header-center "[webpage] :: [page]/[topage]"',
|
30
|
+
'--header-spacing 1',
|
31
|
+
'--header-font-size 8',
|
32
|
+
'--header-line',
|
33
|
+
'--footer-spacing 1',
|
34
|
+
'--footer-font-size 8',
|
35
|
+
'--footer-line',
|
36
|
+
"#{filename}",
|
37
|
+
"#{filename}.pdf",
|
38
|
+
'> /dev/null']
|
39
|
+
_stdin, _stderr, status = Open3.capture3(command.join(' '))
|
40
|
+
fail "Problem processing #{filename}" unless status.success?
|
41
|
+
end
|
42
|
+
|
43
|
+
# Check and verify that the proper softwares are available.
|
44
|
+
#
|
45
|
+
def softwares_installed?
|
46
|
+
AgileUtils::Helper.which('wkhtmltopdf')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/html2pdf/version.rb
CHANGED
data/rubocop-todo.yml
CHANGED
@@ -1,84 +1,39 @@
|
|
1
1
|
# This configuration was generated by `rubocop --auto-gen-config`
|
2
|
-
# on 2014-
|
2
|
+
# on 2014-05-11 21:52:58 +1000 using RuboCop version 0.21.0.
|
3
3
|
# The point is for the user to remove these configuration records
|
4
4
|
# one by one as the offenses are removed from the code base.
|
5
5
|
# Note that changes in the inspected code, or installation of new
|
6
6
|
# versions of RuboCop, may require this file to be generated again.
|
7
7
|
|
8
|
-
# Offense count:
|
8
|
+
# Offense count: 3
|
9
9
|
AmbiguousOperator:
|
10
10
|
Enabled: false
|
11
11
|
|
12
|
-
# Offense count:
|
13
|
-
# Cop supports --auto-correct.
|
14
|
-
# Configuration parameters: PreferredMethods.
|
15
|
-
CollectionMethods:
|
16
|
-
Enabled: false
|
17
|
-
|
18
|
-
# Offense count: 1
|
19
|
-
CyclomaticComplexity:
|
20
|
-
Max: 7
|
21
|
-
|
22
|
-
# Offense count: 5
|
12
|
+
# Offense count: 6
|
23
13
|
Documentation:
|
24
14
|
Enabled: false
|
25
15
|
|
26
|
-
# Offense count: 1
|
27
|
-
# Cop supports --auto-correct.
|
28
|
-
EmptyLinesAroundBody:
|
29
|
-
Enabled: true
|
30
|
-
|
31
16
|
# Offense count: 1
|
32
17
|
# Cop supports --auto-correct.
|
33
18
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
34
19
|
HashSyntax:
|
35
|
-
Enabled: true
|
36
|
-
|
37
|
-
# Offense count: 4
|
38
|
-
# Cop supports --auto-correct.
|
39
|
-
LeadingCommentSpace:
|
40
|
-
Enabled: true
|
20
|
+
Enabled: true`
|
41
21
|
|
42
|
-
# Offense count:
|
22
|
+
# Offense count: 7
|
43
23
|
LineLength:
|
44
|
-
Max:
|
24
|
+
Max: 93
|
45
25
|
|
46
|
-
# Offense count:
|
26
|
+
# Offense count: 2
|
47
27
|
# Configuration parameters: CountComments.
|
48
28
|
MethodLength:
|
49
|
-
Max:
|
29
|
+
Max: 19
|
50
30
|
|
51
31
|
# Offense count: 1
|
52
|
-
|
53
|
-
|
54
|
-
Enabled: true
|
32
|
+
RegexpLiteral:
|
33
|
+
MaxSlashes: 0
|
55
34
|
|
56
|
-
# Offense count:
|
57
|
-
# Cop supports --auto-correct.
|
58
|
-
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
|
59
|
-
SpaceInsideBlockBraces:
|
60
|
-
Enabled: true
|
61
|
-
|
62
|
-
# Offense count: 1
|
63
|
-
# Cop supports --auto-correct.
|
64
|
-
SpecialGlobalVars:
|
65
|
-
Enabled: true
|
66
|
-
|
67
|
-
# Offense count: 16
|
35
|
+
# Offense count: 10
|
68
36
|
# Cop supports --auto-correct.
|
69
37
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
70
38
|
StringLiterals:
|
71
|
-
Enabled: false
|
72
|
-
|
73
|
-
# Offense count: 1
|
74
|
-
UnreachableCode:
|
75
39
|
Enabled: true
|
76
|
-
|
77
|
-
# Offense count: 1
|
78
|
-
UselessAssignment:
|
79
|
-
Enabled: false
|
80
|
-
|
81
|
-
# Offense count: 1
|
82
|
-
# Cop supports --auto-correct.
|
83
|
-
WordArray:
|
84
|
-
MinSize: 2
|
@@ -6,18 +6,18 @@ require 'foodie/generators/recipe'
|
|
6
6
|
|
7
7
|
module Foodie
|
8
8
|
class CLI < Thor
|
9
|
-
desc
|
9
|
+
desc 'portray ITEM', 'Determines if a piece of food is gross or delicious'
|
10
10
|
def portray(name)
|
11
11
|
puts Foodie::Food.portray(name)
|
12
12
|
end
|
13
13
|
|
14
|
-
desc
|
15
|
-
method_option :word, :
|
14
|
+
desc 'pluralize', 'Pluralizes a word'
|
15
|
+
method_option :word, aliases: :word
|
16
16
|
def pluralize
|
17
17
|
puts Foodie::Food.pluralize(options[:word])
|
18
18
|
end
|
19
19
|
|
20
|
-
desc
|
20
|
+
desc 'recipe', 'Generates a recipe scaffold'
|
21
21
|
def recipe(group, name)
|
22
22
|
Foodie::Generators::Recipe.start([group, name])
|
23
23
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
describe Html2Pdf do
|
3
|
+
context '#to_pdf' do
|
4
|
+
it 'raises error on invalid input file' do
|
5
|
+
assert_raises(RuntimeError) { Html2Pdf.to_pdf('bad-file-name') }
|
6
|
+
end
|
7
|
+
end
|
8
|
+
context '#softwares_installed?' do
|
9
|
+
it 'raises error if the requirements are not met' do
|
10
|
+
assert(Html2Pdf.softwares_installed?,
|
11
|
+
'Must have valid installation of `wkhtmltopdf`')
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html2pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Burin Choomnuan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 0.19.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 0.19.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: agile_utils
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 0.0.
|
47
|
+
version: 0.0.9
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.0.
|
54
|
+
version: 0.0.9
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: awesome_print
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -206,7 +206,7 @@ dependencies:
|
|
206
206
|
- - "~>"
|
207
207
|
- !ruby/object:Gem::Version
|
208
208
|
version: '0.8'
|
209
|
-
description: Export html or xhtml
|
209
|
+
description: Export list of html or xhtml files to pdfs with 'wkhtmltopdf'
|
210
210
|
email:
|
211
211
|
- agilecreativity@gmail.com
|
212
212
|
executables:
|
@@ -225,7 +225,7 @@ files:
|
|
225
225
|
- html2pdf.gemspec
|
226
226
|
- lib/html2pdf.rb
|
227
227
|
- lib/html2pdf/cli.rb
|
228
|
-
- lib/html2pdf/
|
228
|
+
- lib/html2pdf/html2pdf.rb
|
229
229
|
- lib/html2pdf/version.rb
|
230
230
|
- rubocop-todo.yml
|
231
231
|
- test/fixtures/samples/demo1_xxx.rb
|
@@ -240,7 +240,7 @@ files:
|
|
240
240
|
- test/fixtures/samples/sub_dir/demo4_xxx.rb
|
241
241
|
- test/fixtures/samples/sub_dir/demo4_xxx.rb.xhtml
|
242
242
|
- test/fixtures/samples/sub_dir/demo4_xxx.rb.xhtml.pdf
|
243
|
-
- test/lib/html2pdf/
|
243
|
+
- test/lib/html2pdf/test_html2pdf.rb
|
244
244
|
- test/test_helper.rb
|
245
245
|
homepage: https://github.com/agilecreativity/html2pdf
|
246
246
|
licenses:
|
@@ -265,20 +265,20 @@ rubyforge_project:
|
|
265
265
|
rubygems_version: 2.2.2
|
266
266
|
signing_key:
|
267
267
|
specification_version: 4
|
268
|
-
summary:
|
268
|
+
summary: Bulk export list of html or xhtml files to pdfs with 'wkhtmltopdf'
|
269
269
|
test_files:
|
270
|
-
- test/
|
271
|
-
- test/test_helper.rb
|
270
|
+
- test/fixtures/samples/demo1_xxx.rb
|
272
271
|
- test/fixtures/samples/demo1_xxx.rb.xhtml
|
272
|
+
- test/fixtures/samples/demo1_xxx.rb.xhtml.pdf
|
273
273
|
- test/fixtures/samples/demo2_xxx.rb
|
274
|
-
- test/fixtures/samples/demo2_xxx.rb.xhtml.pdf
|
275
274
|
- test/fixtures/samples/demo2_xxx.rb.xhtml
|
275
|
+
- test/fixtures/samples/demo2_xxx.rb.xhtml.pdf
|
276
|
+
- test/fixtures/samples/sub_dir/demo3_xxx.rb
|
276
277
|
- test/fixtures/samples/sub_dir/demo3_xxx.rb.xhtml
|
277
|
-
- test/fixtures/samples/sub_dir/demo4_xxx.rb.xhtml.pdf
|
278
278
|
- test/fixtures/samples/sub_dir/demo3_xxx.rb.xhtml.pdf
|
279
|
-
- test/fixtures/samples/sub_dir/demo4_xxx.rb.xhtml
|
280
279
|
- test/fixtures/samples/sub_dir/demo4_xxx.rb
|
281
|
-
- test/fixtures/samples/sub_dir/
|
282
|
-
- test/fixtures/samples/
|
283
|
-
- test/
|
280
|
+
- test/fixtures/samples/sub_dir/demo4_xxx.rb.xhtml
|
281
|
+
- test/fixtures/samples/sub_dir/demo4_xxx.rb.xhtml.pdf
|
282
|
+
- test/lib/html2pdf/test_html2pdf.rb
|
283
|
+
- test/test_helper.rb
|
284
284
|
has_rdoc:
|
data/lib/html2pdf/utils.rb
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require 'fileutils'
|
3
|
-
require_relative '../html2pdf'
|
4
|
-
|
5
|
-
module Html2Pdf
|
6
|
-
module Utils
|
7
|
-
class << self
|
8
|
-
# Batch convert to pdf using `wkhtmltopdf` tool
|
9
|
-
#
|
10
|
-
# @param [Array<String>] files the input file list
|
11
|
-
# @param [String] base_dir the base directory
|
12
|
-
def to_pdfs(files)
|
13
|
-
files.each_with_index do |file, index|
|
14
|
-
puts "Convert file #{index + 1} of #{files.size} : #{file}"
|
15
|
-
to_pdf(file)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
# Convert '*.xhtml' or '*.html' to pdf
|
20
|
-
#
|
21
|
-
# @param filename input filename
|
22
|
-
def to_pdf(filename)
|
23
|
-
fail "Invalid input file #{filename}" unless File.exist?(filename)
|
24
|
-
command = [
|
25
|
-
'wkhtmltopdf',
|
26
|
-
'--margin-top 4',
|
27
|
-
'--margin-bottom 4',
|
28
|
-
'--margin-left 4',
|
29
|
-
'--margin-right 4',
|
30
|
-
'--header-center "[webpage] :: [page]/[topage]"',
|
31
|
-
'--header-spacing 1',
|
32
|
-
'--header-font-size 8',
|
33
|
-
'--header-line',
|
34
|
-
'--footer-spacing 1',
|
35
|
-
'--footer-font-size 8',
|
36
|
-
'--footer-line',
|
37
|
-
"#{filename}",
|
38
|
-
"#{filename}.pdf",
|
39
|
-
'> /dev/null']
|
40
|
-
_stdin, _stderr, status = Open3.capture3(command.join(' '))
|
41
|
-
fail "Problem processing #{filename}" unless status.success?
|
42
|
-
end
|
43
|
-
|
44
|
-
# Check and verify that the proper softwares are available.
|
45
|
-
#
|
46
|
-
def softwares_installed?
|
47
|
-
AgileUtils::Helper.which('wkhtmltopdf')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require_relative '../../test_helper'
|
2
|
-
describe Html2Pdf::Utils do
|
3
|
-
context '#to_pdf' do
|
4
|
-
it 'raises error on invalid input file' do
|
5
|
-
assert_raises(RuntimeError) { Html2Pdf::Utils.to_pdf('bad-file-name') }
|
6
|
-
end
|
7
|
-
end
|
8
|
-
context '#softwares_installed?' do
|
9
|
-
it 'raises error if the requirements are not met' do
|
10
|
-
assert(Html2Pdf::Utils.softwares_installed?,
|
11
|
-
'Must have valid installation of `wkhtmltopdf` and `ghostscript`')
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|