htmlToPdf 0.0.6 → 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 +5 -5
- data/Gemfile.lock +5 -2
- data/README.md +5 -4
- data/htmlToPdf.gemspec +1 -3
- data/lib/htmlToPdf/version.rb +1 -1
- data/lib/htmlToPdf.rb +14 -13
- metadata +12 -15
- data/bin/wkhtmltopdf +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 460c5d0faa74e850b1634f92df685cd99e7a3201eeab67303182c65a789c4462
|
4
|
+
data.tar.gz: e526f651e50ce24683d87d286dd2bec2483f19e5ec037c5d3e24545e0a35cc57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69c80ad936b1eb78f152b2ec5736b9b574cc65f51b808b4a0a1f06af0a7b27c2fa7ebbbe9ddd7a5feff20e7236d9b4d21edaa2611d585bc1bc467f41879d8c25
|
7
|
+
data.tar.gz: 542c42c9495d7b26e9930a83daab667abbe5f1961ae98b3bbd5507c7c5bf211a045f33ae4b1e9c26b1d9ac0da954d454218eef6b1eb015d1330b0579ace1d74a
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
htmlToPdf (0.0
|
4
|
+
htmlToPdf (0.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -12,6 +12,9 @@ PLATFORMS
|
|
12
12
|
ruby
|
13
13
|
|
14
14
|
DEPENDENCIES
|
15
|
-
bundler
|
15
|
+
bundler
|
16
16
|
htmlToPdf!
|
17
17
|
rake
|
18
|
+
|
19
|
+
BUNDLED WITH
|
20
|
+
2.3.26
|
data/README.md
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
Description : this gem will generate pdf of the action's html requested as pdf.
|
4
4
|
|
5
5
|
## Installation
|
6
|
+
#### Install and setup `wkhtmltopdf`. Please refer https://wkhtmltopdf.org for more details.
|
6
7
|
|
7
8
|
Add this line to your application's Gemfile:
|
8
9
|
|
@@ -20,18 +21,18 @@ Or install it yourself as:
|
|
20
21
|
|
21
22
|
write following code inside Application Controller
|
22
23
|
|
23
|
-
|
24
|
+
before_action :html_to_pdf
|
24
25
|
|
25
26
|
in views:
|
26
27
|
|
27
|
-
<%= link_to 'download', your_action_path(:format => 'pdf') %>
|
28
|
+
<%= link_to 'download', your_action_path(:format => 'pdf') %>
|
28
29
|
|
29
30
|
customizing pdf downloads:
|
30
31
|
|
31
32
|
you can customize pdf like you can give the name and layout for the pdf.to customize pdf use this following example:
|
32
33
|
|
33
|
-
|
34
|
+
<%= link_to 'download', your_action_path(:format => 'pdf',:pdf_options => {title: 'pdf_name', layout: 'layout_name'}) %>
|
34
35
|
|
35
|
-
|
36
|
+
this will generate the pdf of your_action named "pdf_name.pdf" with layout "layout_name".
|
36
37
|
|
37
38
|
one can call any action as pdf and he get the pdf file of that action's html.
|
data/htmlToPdf.gemspec
CHANGED
@@ -14,10 +14,8 @@ Gem::Specification.new do |spec|
|
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
17
|
-
spec.executables = ["wkhtmltopdf"]
|
18
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
-
spec.require_paths = ["lib"]
|
20
18
|
|
21
|
-
spec.add_development_dependency "bundler"
|
19
|
+
spec.add_development_dependency "bundler"
|
22
20
|
spec.add_development_dependency "rake"
|
23
21
|
end
|
data/lib/htmlToPdf/version.rb
CHANGED
data/lib/htmlToPdf.rb
CHANGED
@@ -3,40 +3,41 @@ require "htmlToPdf/version"
|
|
3
3
|
module HtmlToPdf
|
4
4
|
|
5
5
|
def html_to_pdf()
|
6
|
-
pdf_options = params[:pdf_options]
|
6
|
+
pdf_options = params[:pdf_options] ? params[:pdf_options] : {}
|
7
7
|
if request.format == 'application/pdf'
|
8
8
|
initialize_downloads(pdf_options)
|
9
9
|
FileUtils.mkdir_p(File.join(Rails.root, 'tmp'))
|
10
10
|
_source_file = File.join(Rails.root, 'tmp', "#{Time.now.to_i.to_s}.html")
|
11
11
|
_destination_file = File.join(Rails.root, 'tmp', "#{@name}.pdf")
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
_controller = ("#{controller_name}Controller").camelize.constantize.new
|
13
|
+
_controller.method(action_name).call
|
14
|
+
_assigns = {}
|
15
|
+
_controller.instance_variables.each do |var|
|
16
|
+
_assigns[var] = _controller.instance_variable_get(var)
|
17
17
|
end
|
18
|
+
_assigns.merge!({url: Rails.application.routes.url_helpers})
|
19
|
+
|
20
|
+
_html = render_to_string(template: "#{controller_name}/#{action_name}", :layout => @layout, locals: _assigns)
|
21
|
+
file_content = _html.gsub(/\\"/, "")
|
22
|
+
|
18
23
|
|
19
24
|
File.open(_source_file, "w+") do |f|
|
20
25
|
f.write(file_content)
|
21
26
|
end
|
22
|
-
|
23
|
-
gem_root = spec.gem_dir
|
24
|
-
gem_lib = gem_root + "/bin"
|
25
|
-
lib_path = "#{gem_lib}/wkhtmltopdf"
|
26
|
-
|
27
|
-
`#{lib_path} #{_source_file} #{_destination_file}`
|
27
|
+
system("wkhtmltopdf #{_source_file} #{_destination_file}")
|
28
28
|
File.delete(_source_file) if File.exist?(_source_file)
|
29
29
|
send_data File.open(_destination_file, "rb") { |f| f.read }, :disposition => 'attachment',:filename => "#{@name}.pdf"
|
30
30
|
File.delete(_destination_file)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
def initialize_downloads(pdf_options)
|
34
|
+
def initialize_downloads(pdf_options = {})
|
35
35
|
if pdf_options
|
36
36
|
@name = pdf_options[:title].nil? ? "#{Time.now.to_i.to_s}" : pdf_options[:title]
|
37
37
|
@layout = pdf_options[:layout].nil? ? 'application' : pdf_options[:layout]
|
38
38
|
else
|
39
39
|
@name = "#{Time.now.to_i.to_s}"
|
40
|
+
@layout = 'application'
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
metadata
CHANGED
@@ -1,48 +1,47 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: htmlToPdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ram Laxman Yadav
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
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'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
description: this gem will generate pdf of given html using wkhtmltopdf
|
42
42
|
email:
|
43
43
|
- yadavramlaxman@gmail.com
|
44
|
-
executables:
|
45
|
-
- wkhtmltopdf
|
44
|
+
executables: []
|
46
45
|
extensions: []
|
47
46
|
extra_rdoc_files: []
|
48
47
|
files:
|
@@ -51,7 +50,6 @@ files:
|
|
51
50
|
- LICENSE.txt
|
52
51
|
- README.md
|
53
52
|
- Rakefile
|
54
|
-
- bin/wkhtmltopdf
|
55
53
|
- htmlToPdf.gemspec
|
56
54
|
- lib/htmlToPdf.rb
|
57
55
|
- lib/htmlToPdf/version.rb
|
@@ -65,17 +63,16 @@ require_paths:
|
|
65
63
|
- lib
|
66
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
67
65
|
requirements:
|
68
|
-
- -
|
66
|
+
- - ">="
|
69
67
|
- !ruby/object:Gem::Version
|
70
68
|
version: '0'
|
71
69
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
70
|
requirements:
|
73
|
-
- -
|
71
|
+
- - ">="
|
74
72
|
- !ruby/object:Gem::Version
|
75
73
|
version: '0'
|
76
74
|
requirements: []
|
77
|
-
|
78
|
-
rubygems_version: 2.2.2
|
75
|
+
rubygems_version: 3.0.9
|
79
76
|
signing_key:
|
80
77
|
specification_version: 4
|
81
78
|
summary: html to pdf converter gem
|
data/bin/wkhtmltopdf
DELETED
Binary file
|