ghtml2pdf 0.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 +7 -0
- data/Changelog.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +91 -0
- data/bin/ghtml2pdf +5 -0
- data/lib/ghtml2pdf/application.rb +59 -0
- data/lib/ghtml2pdf/version.rb +3 -0
- data/lib/ghtml2pdf.rb +8 -0
- metadata +138 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a2cd71696162ba34bf3dee787d03df42e83fc9d2
|
4
|
+
data.tar.gz: b3b8de83e5736ecd62535bf3cc5ea617c2921dcd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c63311016143803e16a3635681d8fe5289174d3cd948f110c07338a8cbfbccceebb8032b99cb811d858463f3e789b390875b9769644763c28b9784e1e50159c5
|
7
|
+
data.tar.gz: 4f5f163a322ffb2af9d8ecf825dcc0b746ef46b0a22fc24d23e483ad09945e71e9f3760ee5b958c4b3bc8ec39d338c09b4a3b6efc76979156f713a5b84c44f63
|
data/Changelog.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Matijs van Zuijlen
|
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,91 @@
|
|
1
|
+
# GHtml2Pdf
|
2
|
+
|
3
|
+
by Matijs van Zuijlen
|
4
|
+
|
5
|
+
## Description
|
6
|
+
|
7
|
+
This will (perhaps) be a HTML to PDF converter based on WebKit2GTK+, using
|
8
|
+
[GirFFI](https://github.com/mvz/gir_ffi) to drive it from Ruby.
|
9
|
+
|
10
|
+
## Why I'm making this
|
11
|
+
|
12
|
+
Wkhtmltopdf annoys me, because:
|
13
|
+
|
14
|
+
* It patches Qt, causing enourmous bloat in the binary
|
15
|
+
* It uses QtWebkit, which is a browser kit not used by any popular browser (not
|
16
|
+
even Konquerer), so no-one really notices if its rendering breaks (and it
|
17
|
+
does)
|
18
|
+
* Building it yourself from source requires several GB of disk space
|
19
|
+
|
20
|
+
## The plan
|
21
|
+
|
22
|
+
Create a clean Ruby implementation of a converter using WebKit to render the
|
23
|
+
HTML and Gtk+'s print functionality to render the PDF. A web view can be
|
24
|
+
rendered offline so no windows should appear. Ideally, we would not want to
|
25
|
+
need X11, but as a workaround I'll use xvfb-run as a wrapper.
|
26
|
+
|
27
|
+
## Status
|
28
|
+
|
29
|
+
This is by no means done yet. If you need something production-ready now, use
|
30
|
+
Wkhtmltopdf or something else! That said, I'd love for people to try this out
|
31
|
+
and provide feedback. Also see Contributing below.
|
32
|
+
|
33
|
+
## Installation
|
34
|
+
|
35
|
+
Add this line to your application's Gemfile:
|
36
|
+
|
37
|
+
gem 'ghtml2pdf'
|
38
|
+
|
39
|
+
And then execute:
|
40
|
+
|
41
|
+
$ bundle
|
42
|
+
|
43
|
+
Or install it yourself as:
|
44
|
+
|
45
|
+
$ gem install ghtml2pdf
|
46
|
+
|
47
|
+
You will also need to install the WebKit2GTK+, the Gtk+ bindings for WebKit2,
|
48
|
+
and gobject-introspection.
|
49
|
+
|
50
|
+
On Debian and Ubuntu, this can be accomplished by installing the packages
|
51
|
+
`libgirepository1.0-dev`, `gobject-introspection` should be enough to get
|
52
|
+
`rake test` working.
|
53
|
+
|
54
|
+
## Usage
|
55
|
+
|
56
|
+
The intended usage will be something like:
|
57
|
+
|
58
|
+
ghtml2pdf input.html output.pdf
|
59
|
+
|
60
|
+
## Development
|
61
|
+
|
62
|
+
After checking out the repo, install dependencies as described under
|
63
|
+
'Installation', and run `bundle install`. Then, run `bundle exec rake spec` to
|
64
|
+
run the tests.
|
65
|
+
|
66
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
67
|
+
|
68
|
+
## Contributing
|
69
|
+
|
70
|
+
All contributions are welcome, so please feel free to file tickets or send pull
|
71
|
+
requests!
|
72
|
+
|
73
|
+
If you want to send pull requests or patches, please try to follow these
|
74
|
+
instructions. If you get stuck, make a pull request anyway and I'll try to help
|
75
|
+
out.
|
76
|
+
|
77
|
+
* Make sure `rake spec` runs without reporting any failures.
|
78
|
+
* Add tests for your feature. Otherwise, I can't see if it works or if I
|
79
|
+
break it later.
|
80
|
+
* Make sure latest master merges cleanly with your branch. Things might
|
81
|
+
have moved around since you forked.
|
82
|
+
* Try not to include changes that are irrelevant to your feature in the
|
83
|
+
same commit.
|
84
|
+
|
85
|
+
You can submit your tickets and pull requests at [GHtml2Pdf's GitHub
|
86
|
+
repository](https://github.com/mvz/ghtml2pdf).
|
87
|
+
|
88
|
+
## License
|
89
|
+
|
90
|
+
The gem is available as open source under the terms of the
|
91
|
+
[MIT License](http://opensource.org/licenses/MIT).
|
data/bin/ghtml2pdf
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'gir_ffi-gtk3'
|
2
|
+
|
3
|
+
module GHtml2Pdf
|
4
|
+
class Application
|
5
|
+
def run
|
6
|
+
input, output, = ARGV
|
7
|
+
unless input
|
8
|
+
warn "An input filename is required"
|
9
|
+
exit 1
|
10
|
+
end
|
11
|
+
unless output
|
12
|
+
warn "An output filename is required"
|
13
|
+
exit 1
|
14
|
+
end
|
15
|
+
input_uri = "file://#{File.expand_path(input)}"
|
16
|
+
output_uri = "file://#{File.expand_path(output)}"
|
17
|
+
|
18
|
+
GirFFI.setup :WebKit2, '4.0'
|
19
|
+
|
20
|
+
Gtk.init
|
21
|
+
|
22
|
+
win = Gtk::OffscreenWindow.new
|
23
|
+
web_view = WebKit2::WebView.new
|
24
|
+
win.add(web_view)
|
25
|
+
|
26
|
+
page_setup = Gtk::PageSetup.new
|
27
|
+
|
28
|
+
print_settings = Gtk::PrintSettings.new
|
29
|
+
print_settings.set_number_up 1
|
30
|
+
print_settings.set_reverse false
|
31
|
+
print_settings.set_print_pages :all
|
32
|
+
print_settings.set 'output-uri', output_uri
|
33
|
+
print_settings.set 'output-file-format', 'pdf'
|
34
|
+
print_settings.set_collate false
|
35
|
+
print_settings.set_n_copies 1
|
36
|
+
print_settings.set_printer 'Print to File'
|
37
|
+
print_settings.set_page_set :all
|
38
|
+
print_settings.set_scale 100.0
|
39
|
+
|
40
|
+
print_operation = WebKit2::PrintOperation.new(web_view)
|
41
|
+
print_operation.page_setup = page_setup
|
42
|
+
print_operation.print_settings = print_settings
|
43
|
+
|
44
|
+
web_view.signal_connect "load-changed" do |_, event, _|
|
45
|
+
case event
|
46
|
+
when :finished
|
47
|
+
print_operation.print
|
48
|
+
sleep 2
|
49
|
+
Gtk.main_quit
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
web_view.load_uri(input_uri)
|
54
|
+
win.show_all
|
55
|
+
|
56
|
+
Gtk.main
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/ghtml2pdf.rb
ADDED
metadata
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ghtml2pdf
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matijs van Zuijlen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gir_ffi-gtk
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.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.8.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.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
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.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: cucumber
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.1'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.1'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: aruba
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.10.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.10.0
|
97
|
+
description: "\n Clean Ruby implemenentation of a HTML to PDF\n converter based
|
98
|
+
on WebKit, WebKit2GTK+ and GirFFI\n "
|
99
|
+
email:
|
100
|
+
- matijs@matijs.net
|
101
|
+
executables:
|
102
|
+
- ghtml2pdf
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- Changelog.md
|
107
|
+
- LICENSE.txt
|
108
|
+
- README.md
|
109
|
+
- bin/ghtml2pdf
|
110
|
+
- lib/ghtml2pdf.rb
|
111
|
+
- lib/ghtml2pdf/application.rb
|
112
|
+
- lib/ghtml2pdf/version.rb
|
113
|
+
homepage: https://github.com/mvz/ghtml2pdf
|
114
|
+
licenses:
|
115
|
+
- MIT
|
116
|
+
metadata: {}
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
requirements: []
|
132
|
+
rubyforge_project:
|
133
|
+
rubygems_version: 2.4.5.1
|
134
|
+
signing_key:
|
135
|
+
specification_version: 4
|
136
|
+
summary: HTML to PDF converter based on WebKit2GTK+
|
137
|
+
test_files: []
|
138
|
+
has_rdoc:
|