page_print 0.1.3 → 0.1.4
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 +139 -116
- data/lib/page_print/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: 24c8d328fc3a7c707f963911d6305fea21cf568e5dc8160356d4a7c09aff9ca6
|
|
4
|
+
data.tar.gz: c7ea027a685ecddae01d267a4d891b1a012cd8275273bcc3363e5c54ca246f91
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bf7f60c19abdec64973d019361abcccc71d795d367f8d3ba96d66a273b28dd7d0f11e81bcc121e6cb099c5b8e7fa71beacaae0b4b20fd01a7e834cd8728ebe95
|
|
7
|
+
data.tar.gz: 0ffd18445dcd38b6b2705c874409e943b31f947d67c577129db3a8e3ed7822f896f8af044fe2e9494927222256eb2034bbe3722d9558287063b613129c0b8cc5
|
data/README.md
CHANGED
|
@@ -1,34 +1,19 @@
|
|
|
1
1
|
# PagePrint
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> [!IMPORTANT]
|
|
4
|
+
> PagePrint is not production-ready yet. The gem is still in active testing, especially around native packaging and platform compatibility.
|
|
4
5
|
|
|
5
|
-
## Requirements
|
|
6
|
-
|
|
7
|
-
- Ruby 3.0+
|
|
8
|
-
- Native gems are published for `x86_64-linux` and `arm64-darwin`.
|
|
9
|
-
- Native gems vendor PlutoBook but compile the small Ruby extension during install so it links against your local Ruby.
|
|
10
|
-
- Source builds on unsupported platforms require PlutoBook development headers and library files.
|
|
11
|
-
|
|
12
|
-
### Source Build Requirements
|
|
13
6
|
|
|
14
|
-
|
|
7
|
+
`page_print` renders HTML strings to PDF files from Ruby using the `plutobook` library through a native C extension.
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
brew install plutobook pkg-config
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
If `pkg-config` cannot find `plutobook`, install the gem with explicit include and library paths:
|
|
21
|
-
|
|
22
|
-
```sh
|
|
23
|
-
gem install page_print -- --with-plutobook-include=/path/to/include --with-plutobook-lib=/path/to/lib
|
|
24
|
-
```
|
|
9
|
+
It exists as a faster, simpler alternative to PDFKit and other `wkhtmltopdf`-based gems. There is no external renderer process to shell out to, and the public Ruby API is intentionally small.
|
|
25
10
|
|
|
26
11
|
## Installation
|
|
27
12
|
|
|
28
13
|
Add PagePrint to your Gemfile:
|
|
29
14
|
|
|
30
15
|
```ruby
|
|
31
|
-
gem "page_print", "~> 0.1.
|
|
16
|
+
gem "page_print", "~> 0.1.4"
|
|
32
17
|
```
|
|
33
18
|
|
|
34
19
|
Or install from RubyGems directly:
|
|
@@ -37,105 +22,11 @@ Or install from RubyGems directly:
|
|
|
37
22
|
gem install page_print
|
|
38
23
|
```
|
|
39
24
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
## Supported Platforms
|
|
43
|
-
|
|
44
|
-
| Platform | Install Type |
|
|
45
|
-
|---|---|
|
|
46
|
-
| `x86_64-linux` | Vendored PlutoBook, local Ruby extension build |
|
|
47
|
-
| `arm64-darwin` | Vendored PlutoBook, local Ruby extension build |
|
|
48
|
-
| Other platforms | Source build |
|
|
49
|
-
|
|
50
|
-
## Local Build
|
|
51
|
-
|
|
52
|
-
Build and install locally:
|
|
53
|
-
|
|
54
|
-
```sh
|
|
55
|
-
gem build page_print.gemspec
|
|
56
|
-
gem install ./page_print-*.gem
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## Development
|
|
60
|
-
|
|
61
|
-
1. Install development dependencies:
|
|
62
|
-
|
|
63
|
-
```sh
|
|
64
|
-
bundle install
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
2. Compile the native extension into `lib/page_print`:
|
|
68
|
-
|
|
69
|
-
```sh
|
|
70
|
-
bundle exec rake compile
|
|
71
|
-
```
|
|
72
|
-
|
|
73
|
-
3. Open an interactive Ruby session against the local checkout:
|
|
74
|
-
|
|
75
|
-
```sh
|
|
76
|
-
bundle exec irb -Ilib
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
Then load the gem from the repo and try it:
|
|
80
|
-
|
|
81
|
-
```ruby
|
|
82
|
-
require "page_print"
|
|
83
|
-
require "tmpdir"
|
|
84
|
-
|
|
85
|
-
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
86
|
-
|
|
87
|
-
PagePrint.html_to_pdf("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
You can also do a quick one-shot smoke test from the shell:
|
|
91
|
-
|
|
92
|
-
```sh
|
|
93
|
-
bundle exec ruby -Ilib -e 'require "tmpdir"; require "page_print"; output_path = File.join(Dir.tmpdir, "page_print-output.pdf"); p PagePrint.html_to_pdf("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)'
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
Or use the development console, which compiles the native extension first and then starts IRB with `PagePrint` loaded:
|
|
97
|
-
|
|
98
|
-
```sh
|
|
99
|
-
bin/console
|
|
100
|
-
```
|
|
101
|
-
|
|
102
|
-
## Running Tests
|
|
103
|
-
|
|
104
|
-
Run the test suite only:
|
|
105
|
-
|
|
106
|
-
```sh
|
|
107
|
-
bundle exec rake test
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
Or run the default rake task, which compiles the extension and then runs tests:
|
|
111
|
-
|
|
112
|
-
```sh
|
|
113
|
-
bundle exec rake
|
|
114
|
-
```
|
|
115
|
-
|
|
116
|
-
## Building Native Gems
|
|
117
|
-
|
|
118
|
-
Build an `x86_64-linux` platform gem with a vendored PlutoBook library:
|
|
119
|
-
|
|
120
|
-
```sh
|
|
121
|
-
bundle exec rake package:linux
|
|
122
|
-
```
|
|
123
|
-
|
|
124
|
-
Build an Apple Silicon macOS platform gem with a vendored PlutoBook library:
|
|
125
|
-
|
|
126
|
-
```sh
|
|
127
|
-
bundle exec rake package:darwin_arm64
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
These tasks check out PlutoBook `v0.17.0`, build it into `lib/page_print/vendor/<platform>`, and write a platform gem to `pkg/`. Platform gems compile the Ruby extension during gem install to avoid tying the gem to the build machine's Ruby version.
|
|
131
|
-
|
|
132
|
-
Native gems bundle PlutoBook and its non-system shared library dependencies. Optional PlutoBook features for curl, TurboJPEG, and WebP are disabled to keep the bundled dependency set smaller.
|
|
133
|
-
|
|
134
|
-
The packaging tasks expect PlutoBook's build dependencies to be installed on the build machine, including Meson, Ninja, pkg-config, Cairo, FreeType, HarfBuzz, Fontconfig, Expat, and ICU.
|
|
25
|
+
Native gems are published for `x86_64-linux` and `arm64-darwin`. Other platforms build from source and require PlutoBook development headers and library files.
|
|
135
26
|
|
|
136
27
|
## Rails Usage
|
|
137
28
|
|
|
138
|
-
PagePrint is
|
|
29
|
+
PagePrint is optimized for Rails applications using Propshaft. In Rails, PagePrint installs a default Propshaft-backed resource fetcher and uses the current request URL as the default `base_url`.
|
|
139
30
|
|
|
140
31
|
Render a PDF from a controller:
|
|
141
32
|
|
|
@@ -228,6 +119,8 @@ PagePrint.configure do |config|
|
|
|
228
119
|
end
|
|
229
120
|
```
|
|
230
121
|
|
|
122
|
+
## Options
|
|
123
|
+
|
|
231
124
|
Supported keyword options:
|
|
232
125
|
|
|
233
126
|
- `base_url:` string used to resolve relative URLs in the HTML
|
|
@@ -241,8 +134,138 @@ Supported keyword options:
|
|
|
241
134
|
|
|
242
135
|
Custom dimensions and margins require `unit:`. Supported units are `:pt`, `:pc`, `:in`, `:cm`, `:mm`, and `:px`.
|
|
243
136
|
|
|
137
|
+
## Benchmarking
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
RUNS=30 WARMUPS=3 bundle exec ruby benchmark/pdf_renderers.rb
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Measured on 2026-05-30 with Ruby 3.4.7 on Apple Silicon:
|
|
144
|
+
|
|
145
|
+
| Renderer | Avg wall | P95 wall | Avg CPU | Avg peak RSS | Avg PDF |
|
|
146
|
+
|---|---:|---:|---:|---:|---:|
|
|
147
|
+
| `page_print` | 78.2ms | 89.6ms | 93.4ms | 42.1MB | 33.0KB |
|
|
148
|
+
| PDFKit | 782.2ms | 2127.1ms | 824.8ms | 59.4MB | 27.9KB |
|
|
149
|
+
|
|
150
|
+
For options and CSV output, see `benchmark/README.md`.
|
|
151
|
+
|
|
152
|
+
## Requirements
|
|
153
|
+
|
|
154
|
+
- Ruby 3.0+
|
|
155
|
+
- Native gems are published for `x86_64-linux` and `arm64-darwin`.
|
|
156
|
+
- Native gems vendor PlutoBook but compile the small Ruby extension during install so it links against your local Ruby.
|
|
157
|
+
- Source builds on unsupported platforms require PlutoBook development headers and library files.
|
|
158
|
+
|
|
159
|
+
Supported platforms:
|
|
160
|
+
|
|
161
|
+
| Platform | Install Type |
|
|
162
|
+
|---|---|
|
|
163
|
+
| `x86_64-linux` | Vendored PlutoBook, local Ruby extension build |
|
|
164
|
+
| `arm64-darwin` | Vendored PlutoBook, local Ruby extension build |
|
|
165
|
+
| Other platforms | Source build |
|
|
166
|
+
|
|
167
|
+
Source build requirements on macOS with Homebrew:
|
|
168
|
+
|
|
169
|
+
```sh
|
|
170
|
+
brew install plutobook pkg-config
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
If `pkg-config` cannot find `plutobook`, install the gem with explicit include and library paths:
|
|
174
|
+
|
|
175
|
+
```sh
|
|
176
|
+
gem install page_print -- --with-plutobook-include=/path/to/include --with-plutobook-lib=/path/to/lib
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
Native gems bundle PlutoBook and required non-system shared libraries. Optional PlutoBook features for curl, TurboJPEG, and WebP are disabled in native gems to keep the bundled dependency set smaller.
|
|
180
|
+
|
|
244
181
|
## Notes
|
|
245
182
|
|
|
246
183
|
- The extension supports writing to a file path with `html_to_pdf` or returning PDF bytes with `html_to_pdf_string`.
|
|
247
184
|
- JavaScript execution is intentionally unsupported.
|
|
248
185
|
- Native gems disable PlutoBook's optional curl, TurboJPEG, and WebP features.
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
Install development dependencies:
|
|
190
|
+
|
|
191
|
+
```sh
|
|
192
|
+
bundle install
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
Compile the native extension into `lib/page_print`:
|
|
196
|
+
|
|
197
|
+
```sh
|
|
198
|
+
bundle exec rake compile
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Open an interactive Ruby session against the local checkout:
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
bundle exec irb -Ilib
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
Then load the gem from the repo and try it:
|
|
208
|
+
|
|
209
|
+
```ruby
|
|
210
|
+
require "page_print"
|
|
211
|
+
require "tmpdir"
|
|
212
|
+
|
|
213
|
+
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
214
|
+
|
|
215
|
+
PagePrint.html_to_pdf("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
You can also do a quick one-shot smoke test from the shell:
|
|
219
|
+
|
|
220
|
+
```sh
|
|
221
|
+
bundle exec ruby -Ilib -e 'require "tmpdir"; require "page_print"; output_path = File.join(Dir.tmpdir, "page_print-output.pdf"); p PagePrint.html_to_pdf("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)'
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
Or use the development console, which compiles the native extension first and then starts IRB with `PagePrint` loaded:
|
|
225
|
+
|
|
226
|
+
```sh
|
|
227
|
+
bin/console
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
## Running Tests
|
|
231
|
+
|
|
232
|
+
Run the test suite only:
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
bundle exec rake test
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
Or run the default rake task, which compiles the extension and then runs tests:
|
|
239
|
+
|
|
240
|
+
```sh
|
|
241
|
+
bundle exec rake
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Local Build
|
|
245
|
+
|
|
246
|
+
Build and install locally:
|
|
247
|
+
|
|
248
|
+
```sh
|
|
249
|
+
gem build page_print.gemspec
|
|
250
|
+
gem install ./page_print-*.gem
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
## Building Native Gems
|
|
254
|
+
|
|
255
|
+
Build an `x86_64-linux` platform gem with a vendored PlutoBook library:
|
|
256
|
+
|
|
257
|
+
```sh
|
|
258
|
+
bundle exec rake package:linux
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Build an Apple Silicon macOS platform gem with a vendored PlutoBook library:
|
|
262
|
+
|
|
263
|
+
```sh
|
|
264
|
+
bundle exec rake package:darwin_arm64
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
These tasks check out PlutoBook `v0.17.0`, build it into `lib/page_print/vendor/<platform>`, and write a platform gem to `pkg/`. Platform gems compile the Ruby extension during gem install to avoid tying the gem to the build machine's Ruby version.
|
|
268
|
+
|
|
269
|
+
Native gems bundle PlutoBook and its non-system shared library dependencies. Optional PlutoBook features for curl, TurboJPEG, and WebP are disabled to keep the bundled dependency set smaller.
|
|
270
|
+
|
|
271
|
+
The packaging tasks expect PlutoBook's build dependencies to be installed on the build machine, including Meson, Ninja, pkg-config, Cairo, FreeType, HarfBuzz, Fontconfig, Expat, and ICU.
|
data/lib/page_print/version.rb
CHANGED