palapala_pdf 0.1.12 → 0.1.13
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/README.md +58 -7
- data/examples/headers_and_footers.pdf +0 -0
- data/examples/headers_and_footers.rb +2 -1
- data/examples/js_based_rendering.pdf +0 -0
- data/examples/paged_css.pdf +0 -0
- data/lib/palapala/pdf.rb +20 -1
- data/lib/palapala/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a5231c5a9994723db5fafc42682644a6320a69813444bc0939e179225e7181b
|
4
|
+
data.tar.gz: 5f3600f8fb867ee059e1a67fcda2eeeff0d7f290c8621d8bc055e6fb4cbda39c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a50a38a6482f04f7af087b0469d0fcf0d5bc02e79f3ad2fe26a91c5b06aa07345fe15b99472355eab1daef95c3069d54e1d9990820b401872681172b278f43d2
|
7
|
+
data.tar.gz: 2697106dfcad72207bd20fcad857c9a474ffacf49a67fa10e1d2801a8b5c41226e9d9b7145066b78f6dc002dc951f706c1f5fd83c346b196674f59294d124bc0
|
data/README.md
CHANGED
@@ -75,7 +75,7 @@ HEADLESS_CHROME_URL=http://192.168.1.1:9222 ruby examples/performance_benchmark.
|
|
75
75
|
```
|
76
76
|
|
77
77
|
```sh
|
78
|
-
|
78
|
+
HEADLESS_CHROME_PATH=/var/to/chrome ruby examples/performance_benchmark.rb
|
79
79
|
```
|
80
80
|
|
81
81
|
**Create a PDF from HTML**
|
@@ -97,6 +97,7 @@ binary_data = Palapala::Pdf.new("<h1>Hello, world! #{Time.now}</h1>").binary_dat
|
|
97
97
|
## Advanced Examples
|
98
98
|
|
99
99
|
- headers and footers
|
100
|
+
- watermark
|
100
101
|
- paged css for paper sizes, paper margins, pages breaks, etc
|
101
102
|
- js based rendering
|
102
103
|
|
@@ -189,7 +190,29 @@ In this example, `pdf_data` is the binary data of the PDF file. The `filename` o
|
|
189
190
|
|
190
191
|
TODO
|
191
192
|
|
192
|
-
|
193
|
+
```Dockerfile
|
194
|
+
# Install Nodejs and Chromium, to import the chrome headless shell dependencies easily (chrome itself is not used)
|
195
|
+
RUN curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && apt-get install --no-install-recommends -y nodejs chromium && \
|
196
|
+
rm -rf /var/lib/apthet/lists /var/cache/apt/archives
|
197
|
+
|
198
|
+
# Install Chrome Headless Shell
|
199
|
+
RUN npx --yes @puppeteer/browsers install chrome-headless-shell@stable
|
200
|
+
```
|
201
|
+
|
202
|
+
Use a script like the below, to launch chrome headless shell from e.g. docker entrypoint script.
|
203
|
+
|
204
|
+
*launch_chrome_headless_shell.rb*
|
205
|
+
|
206
|
+
```sh
|
207
|
+
#!/bin/bash
|
208
|
+
# find the installation path of chrome headless shell (latest version)
|
209
|
+
export CHROME_PATH=$(npx --yes @puppeteer/browsers install chrome-headless-shell@stable | awk '{print $2}')
|
210
|
+
# start chrome headless with remote debugging on
|
211
|
+
$CHROME_PATH --disable-gpu --remote-debugging-port=9222 --disable-software-rasterizer --disable-bluetooth --no-sandbox
|
212
|
+
```
|
213
|
+
|
214
|
+
*It has also been reported that the Chrome process repeatedly crashes when running inside a Docker container on an M1 Mac. Chrome should work asexpected when deployed to a Docker container on a non-M1 Mac.*
|
215
|
+
|
193
216
|
|
194
217
|
## Thread-safety
|
195
218
|
|
@@ -203,12 +226,40 @@ thread safe in the sense that every web socket get's a new tab in the underlying
|
|
203
226
|
|
204
227
|
TODO
|
205
228
|
|
206
|
-
|
229
|
+
This buildpack installs chrome and chromedriver (chromedriver is actually not needed, but at least the buildpack is maintained)
|
207
230
|
|
208
|
-
|
231
|
+
```sh
|
232
|
+
https://elements.heroku.com/buildpacks/heroku/heroku-buildpack-google-chrome
|
233
|
+
```
|
209
234
|
|
210
|
-
|
235
|
+
### launch as child process
|
211
236
|
|
212
|
-
|
237
|
+
set `HEADLESS_CHROME_PATH=chrome` as an ENV variable as this buildpacks adds `chrome` to the path.
|
213
238
|
|
214
|
-
|
239
|
+
### run seperately
|
240
|
+
|
241
|
+
In your `Procfile` adjust the web worker command
|
242
|
+
|
243
|
+
```yaml
|
244
|
+
web: bin/start
|
245
|
+
```
|
246
|
+
|
247
|
+
Create a bin/start script
|
248
|
+
|
249
|
+
```sh
|
250
|
+
#!/bin/bash
|
251
|
+
# Start Rails app
|
252
|
+
bundle exec rails server -p $PORT -e $RAILS_ENV &
|
253
|
+
|
254
|
+
# Start the background app
|
255
|
+
command_to_start_your_background_app &
|
256
|
+
|
257
|
+
# Wait for all processes to finish
|
258
|
+
wait -n
|
259
|
+
```
|
260
|
+
|
261
|
+
ensure the script is executable
|
262
|
+
|
263
|
+
```sh
|
264
|
+
chmod +x bin/start
|
265
|
+
```
|
Binary file
|
@@ -23,7 +23,8 @@ Palapala::Pdf.new(
|
|
23
23
|
footer:,
|
24
24
|
margin_top: 1,
|
25
25
|
margin_left: 1,
|
26
|
-
margin_bottom: 1
|
26
|
+
margin_bottom: 1,
|
27
|
+
watermark: "DRAFT").save('headers_and_footers.pdf')
|
27
28
|
|
28
29
|
puts "Generated headers_and_footers.pdf"
|
29
30
|
# `open headers_and_footers.pdf`
|
Binary file
|
data/examples/paged_css.pdf
CHANGED
Binary file
|
data/lib/palapala/pdf.rb
CHANGED
@@ -43,7 +43,8 @@ module Palapala
|
|
43
43
|
paper_width: nil,
|
44
44
|
prefer_css_page_size: nil,
|
45
45
|
print_background: nil,
|
46
|
-
scale: nil
|
46
|
+
scale: nil,
|
47
|
+
watermark: nil)
|
47
48
|
@content = content || raise(ArgumentError, "Content is required and can't be nil")
|
48
49
|
@opts = {}
|
49
50
|
raise(ArgumentError, "Either footer or footer_template is expected") if !footer_template.nil? && !footer.nil?
|
@@ -62,11 +63,29 @@ module Palapala
|
|
62
63
|
@opts[:preferCSSPageSize] = prefer_css_page_size || Palapala.defaults[:prefer_css_page_size]
|
63
64
|
@opts[:printBackground] = print_background || Palapala.defaults[:print_background]
|
64
65
|
@opts[:scale] = scale || Palapala.defaults[:scale]
|
66
|
+
@opts[:headerTemplate] = (@opts[:headerTemplate].to_s + watermark(watermark)) if watermark
|
65
67
|
@opts[:displayHeaderFooter] = (@opts[:headerTemplate] || @opts[:footerTemplate]) ? true : false
|
66
68
|
@opts[:encoding] = :binary
|
67
69
|
@opts.compact!
|
68
70
|
end
|
69
71
|
|
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
|
+
|
70
89
|
def hf_template(from:)
|
71
90
|
return if from.nil?
|
72
91
|
style = <<~HTML.freeze
|
data/lib/palapala/version.rb
CHANGED