palapala_pdf 0.1.13 → 0.1.15
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/headers_and_footers.pdf +0 -0
- data/examples/headers_and_footers.rb +1 -1
- data/examples/js_based_rendering.pdf +0 -0
- data/examples/paged_css.pdf +0 -0
- data/lib/palapala/helper.rb +54 -0
- data/lib/palapala/pdf.rb +6 -34
- data/lib/palapala/version.rb +1 -1
- data/lib/palapala.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb2b592eddfeb0f59e676024799d3042f7244a009ef1df2404ce70b47b917a8e
|
4
|
+
data.tar.gz: 2759e4fdfabc81dcf85271bcd7caaab869dfeea54f2702f8f334a962cbf82168
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 39523b9ea30d700456961862236ca0405a9e7311d7c99d81a8c9c0ed73df0b1088b2c9bedf143bc947e95030147cb8da63d9cb4cc102efea34b865919d371e84
|
7
|
+
data.tar.gz: 24958e43641f78b024e4848888f19cb7c6d688304486baad281320ab8a3f1bc443ab012f85a51fff174969b047356b89461436529e07f906d8e7c9b3294c02a2
|
Binary file
|
@@ -24,7 +24,7 @@ Palapala::Pdf.new(
|
|
24
24
|
margin_top: 1,
|
25
25
|
margin_left: 1,
|
26
26
|
margin_bottom: 1,
|
27
|
-
watermark: "
|
27
|
+
watermark: "CLASSIFIED").save('headers_and_footers.pdf')
|
28
28
|
|
29
29
|
puts "Generated headers_and_footers.pdf"
|
30
30
|
# `open headers_and_footers.pdf`
|
Binary file
|
data/examples/paged_css.pdf
CHANGED
Binary file
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Palapala
|
2
|
+
module Helper
|
3
|
+
def self.header(left: "", center: "", right: "", margin: "1cm")
|
4
|
+
<<~HTML
|
5
|
+
<div style="display: flex; justify-content: space-between; width: 100%; margin-left: #{margin}; margin-right: #{margin};">
|
6
|
+
<div style="text-align: left; flex: 1;">#{left}</div>
|
7
|
+
<div style="text-align: center; flex: 1;">#{center}</div>
|
8
|
+
<div style="text-align: right; flex: 1;">#{right}</div>
|
9
|
+
</div>
|
10
|
+
HTML
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.footer(left: "", center: "", right: "", margin: "1cm")
|
14
|
+
self.header(left:, center:, right:, margin:)
|
15
|
+
end
|
16
|
+
``
|
17
|
+
def self.page_number
|
18
|
+
<<~HTML
|
19
|
+
<span class="pageNumber"></span>/<span class="totalPages"></span>
|
20
|
+
HTML
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.watermark(watermark, angle: "-15deg", color: "rgba(25,25,25,0.25)", font_size: "72pt")
|
24
|
+
<<~HTML
|
25
|
+
<style>
|
26
|
+
.palapala_pdf_watermark {
|
27
|
+
position: fixed;
|
28
|
+
top: 50%;
|
29
|
+
left: 50%;
|
30
|
+
transform: translate(-50%, -50%) rotate(#{angle});
|
31
|
+
font-size: #{font_size};
|
32
|
+
color: #{color};
|
33
|
+
z-index: 9999;
|
34
|
+
}
|
35
|
+
</style>
|
36
|
+
<span class="palapala_pdf_watermark">#{watermark}</span>
|
37
|
+
HTML
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.hf_template(from:)
|
41
|
+
return if from.nil?
|
42
|
+
style = <<~HTML.freeze
|
43
|
+
<style>
|
44
|
+
#header, #footer {
|
45
|
+
font-size: 10pt;
|
46
|
+
display: flex;
|
47
|
+
justify-content: center;
|
48
|
+
}
|
49
|
+
</style>
|
50
|
+
HTML
|
51
|
+
style + from
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
data/lib/palapala/pdf.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require_relative "./renderer"
|
2
|
+
require_relative "./helper"
|
2
3
|
|
3
4
|
module Palapala
|
4
5
|
# Page class to generate PDF from HTML content using Chrome in headless mode in a thread-safe way
|
@@ -49,8 +50,8 @@ module Palapala
|
|
49
50
|
@opts = {}
|
50
51
|
raise(ArgumentError, "Either footer or footer_template is expected") if !footer_template.nil? && !footer.nil?
|
51
52
|
raise(ArgumentError, "Either header or header_template is expected") if !header_template.nil? && !header.nil?
|
52
|
-
@opts[:headerTemplate] = header_template || hf_template(from: header) || Palapala.defaults[:header_template]
|
53
|
-
@opts[:footerTemplate] = footer_template || hf_template(from: footer) || Palapala.defaults[:footer_template]
|
53
|
+
@opts[:headerTemplate] = header_template || Helper.hf_template(from: header) || Palapala.defaults[:header_template]
|
54
|
+
@opts[:footerTemplate] = footer_template || Helper.hf_template(from: footer) || Palapala.defaults[:footer_template]
|
54
55
|
@opts[:pageRanges] = page_ranges || Palapala.defaults[:page_ranges]
|
55
56
|
@opts[:generateTaggedPDF] = generate_tagged_pdf || Palapala.defaults[:generate_tagged_pdf]
|
56
57
|
@opts[:paperWidth] = paper_width || Palapala.defaults[:paper_width]
|
@@ -63,43 +64,14 @@ module Palapala
|
|
63
64
|
@opts[:preferCSSPageSize] = prefer_css_page_size || Palapala.defaults[:prefer_css_page_size]
|
64
65
|
@opts[:printBackground] = print_background || Palapala.defaults[:print_background]
|
65
66
|
@opts[:scale] = scale || Palapala.defaults[:scale]
|
66
|
-
@opts[:headerTemplate] = (@opts[:headerTemplate].to_s + watermark(watermark)) if watermark
|
67
|
+
@opts[:headerTemplate] = (@opts[:headerTemplate].to_s + Helper.watermark(watermark)) if watermark
|
67
68
|
@opts[:displayHeaderFooter] = (@opts[:headerTemplate] || @opts[:footerTemplate]) ? true : false
|
69
|
+
@opts[:headerTemplate] ||= " " if @opts[:displayHeaderFooter]
|
70
|
+
@opts[:footerTemplate] ||= " " if @opts[:displayHeaderFooter]
|
68
71
|
@opts[:encoding] = :binary
|
69
72
|
@opts.compact!
|
70
73
|
end
|
71
74
|
|
72
|
-
def watermark(watermark, angle: "-15deg", color: "rgba(25,25,25,0.25)")
|
73
|
-
<<~HTML
|
74
|
-
<style>
|
75
|
-
.palapala_pdf_watermark {
|
76
|
-
position: fixed;
|
77
|
-
top: 50%;
|
78
|
-
left: 50%;
|
79
|
-
transform: translate(-50%, -50%) rotate(#{angle});
|
80
|
-
font-size: 8em;
|
81
|
-
color: #{color};
|
82
|
-
z-index: 9999;
|
83
|
-
}
|
84
|
-
</style>
|
85
|
-
<span class="palapala_pdf_watermark">#{watermark}</span>
|
86
|
-
HTML
|
87
|
-
end
|
88
|
-
|
89
|
-
def hf_template(from:)
|
90
|
-
return if from.nil?
|
91
|
-
style = <<~HTML.freeze
|
92
|
-
<style>
|
93
|
-
#header, #footer {
|
94
|
-
font-size: 10pt;
|
95
|
-
display: flex;
|
96
|
-
justify-content: center;
|
97
|
-
}
|
98
|
-
</style>
|
99
|
-
HTML
|
100
|
-
style + from
|
101
|
-
end
|
102
|
-
|
103
75
|
# Render the PDF content to a binary string.
|
104
76
|
#
|
105
77
|
# The params from the initializer are converted to the expected casing and merged with the options passed to this method.
|
data/lib/palapala/version.rb
CHANGED
data/lib/palapala.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: palapala_pdf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koen Handekyn
|
@@ -69,6 +69,7 @@ files:
|
|
69
69
|
- examples/performance_benchmark.rb
|
70
70
|
- lib/palapala.rb
|
71
71
|
- lib/palapala/chrome_process.rb
|
72
|
+
- lib/palapala/helper.rb
|
72
73
|
- lib/palapala/pdf.rb
|
73
74
|
- lib/palapala/renderer.rb
|
74
75
|
- lib/palapala/version.rb
|