html2pdf 0.1.6 → 0.1.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/.rubocop.yml +2 -2
- data/CHANGELOG.md +6 -0
- data/README.md +76 -6
- data/Rakefile +1 -1
- data/bin/html2pdf +6 -1
- data/config/initializers/html2pdf.rb +28 -0
- data/html2pdf.gemspec +2 -2
- data/lib/html2pdf/cli.rb +2 -0
- data/lib/html2pdf/configuration.rb +49 -0
- data/lib/html2pdf/html2pdf.rb +8 -15
- data/lib/html2pdf/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d51f99366f1cdaef945c9e434fdc1a14647380c0
|
4
|
+
data.tar.gz: f4ebe2bc4f9d4fc410883cecce69227219e01e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 82969eb4ccba80407ff5438d3feb237884fbfbd686a8a5d442c76763d85564e41b36ae1393b190b2a78890c334dd53a81e78e7d7cb16098c390f990007caff0a
|
7
|
+
data.tar.gz: 8d7001ccc60907d7199a2959fba38e92efd970302fc23ed3fb0e253d90275717740d57e3caa66f3956cc2a41418798d4bfb23a6a8e7b65014e858362e99ec2c7
|
data/.rubocop.yml
CHANGED
@@ -48,9 +48,9 @@ Documentation:
|
|
48
48
|
HashSyntax:
|
49
49
|
Enabled: true
|
50
50
|
|
51
|
-
#
|
51
|
+
# spaces inside hash literals
|
52
52
|
SpaceInsideHashLiteralBraces:
|
53
|
-
EnforcedStyle:
|
53
|
+
EnforcedStyle: space
|
54
54
|
|
55
55
|
# Allow dots at the end of lines
|
56
56
|
DotPosition:
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
### Changelogs for html2pdf
|
2
2
|
|
3
|
+
#### 0.1.7
|
4
|
+
|
5
|
+
- Add `--disable-smart-shrinking` option in wkhtmltopdf
|
6
|
+
- Update `rubocop` to 0.23.x version
|
7
|
+
- Allow the customization through configuration
|
8
|
+
|
3
9
|
#### 0.1.6
|
4
10
|
|
5
11
|
- Make use of the starting directory in the output filename
|
data/README.md
CHANGED
@@ -18,12 +18,7 @@ Note: starting from version `0.1.0` this gem will be release based on [Semantic
|
|
18
18
|
|
19
19
|
- [wkhtmltopdf][] - please see [wkhtmltopdf installation][] for detail
|
20
20
|
|
21
|
-
###
|
22
|
-
|
23
|
-
- wkhtmltopdf (Linux/OSX)
|
24
|
-
- OSX or Linux
|
25
|
-
|
26
|
-
## Usage
|
21
|
+
### Usage
|
27
22
|
|
28
23
|
```sh
|
29
24
|
gem install html2pdf
|
@@ -91,6 +86,80 @@ the pdf version of it.
|
|
91
86
|
|
92
87
|
- Then combine the generated pdf files using [pdfs2pdf][] gem to produce one pdf file
|
93
88
|
|
89
|
+
### Customization
|
90
|
+
|
91
|
+
If you like to adjust the output for pdf you can override the default settings by
|
92
|
+
set your own configuration in the file `config/initializers/html2pdf.rb`
|
93
|
+
|
94
|
+
For more customization please see the [wkhtmltopdf manual][] page for detail.
|
95
|
+
|
96
|
+
```ruby
|
97
|
+
require_relative "../../lib/html2pdf/configuration"
|
98
|
+
module Html2Pdf
|
99
|
+
class << self
|
100
|
+
# rubocop:disable MethodLength
|
101
|
+
def update_config
|
102
|
+
Html2Pdf.configure do |config|
|
103
|
+
# Note: or add your own path here if `wkhtmltopdf` is not in the $PATH environment
|
104
|
+
config.options[:wkhtmltopdf] = (defined?(Bundler::GemfileError) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
|
105
|
+
config.options[:page_settings] = [
|
106
|
+
"--margin-top 8",
|
107
|
+
"--margin-bottom 8",
|
108
|
+
"--margin-left 8",
|
109
|
+
"--margin-right 8",
|
110
|
+
'--header-center "[webpage] :: [page]/[topage]"',
|
111
|
+
"--header-spacing 1",
|
112
|
+
"--header-font-size 8",
|
113
|
+
"--header-line",
|
114
|
+
"--footer-spacing 1",
|
115
|
+
"--footer-font-size 8",
|
116
|
+
"--footer-line"
|
117
|
+
]
|
118
|
+
end
|
119
|
+
end
|
120
|
+
# rubocop:enable All
|
121
|
+
end
|
122
|
+
end
|
123
|
+
```
|
124
|
+
|
125
|
+
You can use the custom settings by loading it in the `bin/html2pdf` like:
|
126
|
+
|
127
|
+
```ruby
|
128
|
+
#!/usr/bin/env ruby
|
129
|
+
require_relative "../lib/html2pdf"
|
130
|
+
# Note: if you like to customize the settings for `wkhtmltopdf` then
|
131
|
+
# uncomment the next two lines
|
132
|
+
# -----------------------------------------------------------------#
|
133
|
+
require_relative "../config/initializers/html2pdf"
|
134
|
+
Html2Pdf.update_config
|
135
|
+
# -----------------------------------------------------------------#
|
136
|
+
if ARGV.empty?
|
137
|
+
Html2Pdf::CLI.start(%w[usage])
|
138
|
+
else
|
139
|
+
Html2Pdf::CLI.start(%w[export].concat(ARGV))
|
140
|
+
end
|
141
|
+
```
|
142
|
+
|
143
|
+
Note: by default the above configuration is configured in
|
144
|
+
the file `./lib/html2pdf/configuration.rb`. Which contain the following values
|
145
|
+
|
146
|
+
```ruby
|
147
|
+
wkhtmltopdf = (defined?(Bundler::GemfileError) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp,
|
148
|
+
page_settings = [
|
149
|
+
"--margin-top 4",
|
150
|
+
"--margin-bottom 4",
|
151
|
+
"--margin-left 4",
|
152
|
+
"--margin-right 4",
|
153
|
+
'--header-center "[webpage] :: [page]/[topage]"',
|
154
|
+
"--header-spacing 1",
|
155
|
+
"--header-font-size 8",
|
156
|
+
"--header-line",
|
157
|
+
"--footer-spacing 1",
|
158
|
+
"--footer-font-size 8",
|
159
|
+
"--footer-line"
|
160
|
+
]
|
161
|
+
```
|
162
|
+
|
94
163
|
### Contributing
|
95
164
|
|
96
165
|
1. Fork it ( http://github.com/agilecreativity/html2pdf/fork )
|
@@ -103,4 +172,5 @@ the pdf version of it.
|
|
103
172
|
[pdfs2pdf]: https://github.com/agilecreativity/pdfs2pdf
|
104
173
|
[wkhtmltopdf]: http://wkhtmltopdf.org/
|
105
174
|
[wkhtmltopdf installation]: https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF
|
175
|
+
[wkhtmltopdf manual]: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
|
106
176
|
[Semantic Versioning]: http://semver.org
|
data/Rakefile
CHANGED
@@ -20,7 +20,7 @@ end
|
|
20
20
|
|
21
21
|
require "rubocop/rake_task"
|
22
22
|
desc "Run RuboCop on the lib directory"
|
23
|
-
|
23
|
+
RuboCop::RakeTask.new(:rubocop) do |task|
|
24
24
|
task.patterns = ["lib/**/*.rb"]
|
25
25
|
# only show the files with failures
|
26
26
|
task.formatters = ["files"]
|
data/bin/html2pdf
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require_relative "../lib/html2pdf"
|
3
|
-
|
3
|
+
# If you like to customize the settings for `wkhtmltopdf` then
|
4
|
+
# edit the file `config/initializers/html2pdf.rb` and enable it in the next 2 lines
|
5
|
+
# -----------------------------------------------------------------#
|
6
|
+
# require_relative "../config/initializers/html2pdf"
|
7
|
+
# Html2Pdf.update_config
|
8
|
+
# -----------------------------------------------------------------#
|
4
9
|
if ARGV.empty?
|
5
10
|
Html2Pdf::CLI.start(%w[usage])
|
6
11
|
else
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "../../lib/html2pdf/configuration"
|
2
|
+
module Html2Pdf
|
3
|
+
class << self
|
4
|
+
# Customize the configuration for specific system (Ubuntu/OSX/etc)
|
5
|
+
# See: ./lib/html2pdf/configuration.rb for available options
|
6
|
+
# rubocop:disable MethodLength
|
7
|
+
def update_config
|
8
|
+
Html2Pdf.configure do |config|
|
9
|
+
# Note: or add your own path here if `wkhtmltopdf` is not in the $PATH environment
|
10
|
+
config.options[:wkhtmltopdf] = (defined?(Bundler::GemfileError) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp
|
11
|
+
config.options[:page_settings] = [
|
12
|
+
"--margin-top 8",
|
13
|
+
"--margin-bottom 8",
|
14
|
+
"--margin-left 8",
|
15
|
+
"--margin-right 8",
|
16
|
+
'--header-center "[webpage] :: [page]/[topage]"',
|
17
|
+
"--header-spacing 1",
|
18
|
+
"--header-font-size 8",
|
19
|
+
"--header-line",
|
20
|
+
"--footer-spacing 1",
|
21
|
+
"--footer-font-size 8",
|
22
|
+
"--footer-line"
|
23
|
+
]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
# rubocop:enable All
|
27
|
+
end
|
28
|
+
end
|
data/html2pdf.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
|
|
12
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
|
-
spec.files = Dir.glob("{bin,lib}/**/*") + %w[Gemfile
|
15
|
+
spec.files = Dir.glob("{bin,lib,config}/**/*") + %w[Gemfile
|
16
16
|
Rakefile
|
17
17
|
html2pdf.gemspec
|
18
18
|
README.md
|
@@ -35,6 +35,6 @@ Gem::Specification.new do |spec|
|
|
35
35
|
spec.add_development_dependency "minitest-spec-context", "~> 0.0.3"
|
36
36
|
spec.add_development_dependency "pry", "~> 0.9"
|
37
37
|
spec.add_development_dependency "rake", "~> 10.1"
|
38
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
38
|
+
spec.add_development_dependency "rubocop", "~> 0.23"
|
39
39
|
spec.add_development_dependency "yard", "~> 0.8"
|
40
40
|
end
|
data/lib/html2pdf/cli.rb
CHANGED
@@ -4,6 +4,7 @@ require "fileutils"
|
|
4
4
|
require_relative "../html2pdf"
|
5
5
|
module Html2Pdf
|
6
6
|
class CLI < Thor
|
7
|
+
# rubocop:disable AmbiguousOperator, MethodLength
|
7
8
|
desc "export", "export multiple html files to pdfs"
|
8
9
|
method_option *AgileUtils::Options::BASE_DIR
|
9
10
|
method_option *AgileUtils::Options::RECURSIVE
|
@@ -38,6 +39,7 @@ module Html2Pdf
|
|
38
39
|
puts "Convert files to pdfs took #{elapsed} ms"
|
39
40
|
puts "Your final output is '#{File.absolute_path(output_file)}'"
|
40
41
|
end
|
42
|
+
# rubocop:enable All
|
41
43
|
|
42
44
|
desc "usage", "Display usage information"
|
43
45
|
def usage
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Html2Pdf
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :options
|
4
|
+
# rubocop:disable MethodLength
|
5
|
+
def initialize
|
6
|
+
# see: http://wkhtmltopdf.org/usage/wkhtmltopdf.txt
|
7
|
+
@options = {
|
8
|
+
wkhtmltopdf: (defined?(Bundler::GemfileError) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp,
|
9
|
+
page_settings: [
|
10
|
+
"--margin-top 4",
|
11
|
+
"--margin-bottom 4",
|
12
|
+
"--margin-left 4",
|
13
|
+
"--margin-right 4",
|
14
|
+
'--header-center "[webpage] :: [page]/[topage]"',
|
15
|
+
"--header-spacing 1",
|
16
|
+
"--header-font-size 8",
|
17
|
+
"--header-line",
|
18
|
+
"--footer-spacing 1",
|
19
|
+
"--footer-font-size 8",
|
20
|
+
"--footer-line"
|
21
|
+
]
|
22
|
+
}
|
23
|
+
end
|
24
|
+
# rubocop:enable All
|
25
|
+
end
|
26
|
+
|
27
|
+
class << self
|
28
|
+
attr_accessor :configuration
|
29
|
+
|
30
|
+
# Configure Pdfs2Pdf someplace sensible, like
|
31
|
+
# config/initializers/html2pdf.rb
|
32
|
+
#
|
33
|
+
# Html2Pdf.configure do |config|
|
34
|
+
# # set appropriate options
|
35
|
+
# config.options[:wkhtmltopdf] = '/usr/bin/wkhtmltopdf'
|
36
|
+
# config.options[:page_settings] = [ "--margin-top 4",
|
37
|
+
# "--margin-bottom 4",
|
38
|
+
# ..
|
39
|
+
# ]
|
40
|
+
# end
|
41
|
+
def configuration
|
42
|
+
@configuration ||= Configuration.new
|
43
|
+
end
|
44
|
+
|
45
|
+
def configure
|
46
|
+
yield(configuration)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/html2pdf/html2pdf.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require "open3"
|
2
2
|
require "fileutils"
|
3
3
|
require_relative "../html2pdf"
|
4
|
+
require_relative "./configuration"
|
4
5
|
module Html2Pdf
|
5
6
|
class << self
|
6
7
|
# Batch convert to pdf using `wkhtmltopdf` tool
|
@@ -19,23 +20,15 @@ module Html2Pdf
|
|
19
20
|
# @param filename input filename
|
20
21
|
def to_pdf(filename)
|
21
22
|
fail "Invalid input file #{filename}" unless File.exist?(filename)
|
22
|
-
|
23
|
+
wkhtmltopdf = Html2Pdf.configuration.options[:wkhtmltopdf]
|
24
|
+
page_settings = Html2Pdf.configuration.options[:page_settings]
|
23
25
|
command = [
|
24
|
-
|
25
|
-
|
26
|
-
|
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}",
|
26
|
+
wkhtmltopdf,
|
27
|
+
*page_settings,
|
28
|
+
filename,
|
37
29
|
"#{filename}.pdf",
|
38
|
-
"> /dev/null"
|
30
|
+
"> /dev/null"
|
31
|
+
]
|
39
32
|
_stdin, _stderr, status = Open3.capture3(command.join(" "))
|
40
33
|
fail "Problem processing #{filename}" unless status.success?
|
41
34
|
end
|
data/lib/html2pdf/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: html2pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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-06-
|
11
|
+
date: 2014-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -184,14 +184,14 @@ dependencies:
|
|
184
184
|
requirements:
|
185
185
|
- - "~>"
|
186
186
|
- !ruby/object:Gem::Version
|
187
|
-
version: '0.
|
187
|
+
version: '0.23'
|
188
188
|
type: :development
|
189
189
|
prerelease: false
|
190
190
|
version_requirements: !ruby/object:Gem::Requirement
|
191
191
|
requirements:
|
192
192
|
- - "~>"
|
193
193
|
- !ruby/object:Gem::Version
|
194
|
-
version: '0.
|
194
|
+
version: '0.23'
|
195
195
|
- !ruby/object:Gem::Dependency
|
196
196
|
name: yard
|
197
197
|
requirement: !ruby/object:Gem::Requirement
|
@@ -222,9 +222,11 @@ files:
|
|
222
222
|
- README.md
|
223
223
|
- Rakefile
|
224
224
|
- bin/html2pdf
|
225
|
+
- config/initializers/html2pdf.rb
|
225
226
|
- html2pdf.gemspec
|
226
227
|
- lib/html2pdf.rb
|
227
228
|
- lib/html2pdf/cli.rb
|
229
|
+
- lib/html2pdf/configuration.rb
|
228
230
|
- lib/html2pdf/html2pdf.rb
|
229
231
|
- lib/html2pdf/version.rb
|
230
232
|
- test/fixtures/samples/demo1_xxx.rb
|