page_print 0.1.7 → 0.1.9
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 +12 -13
- data/ext/page_print/page_print.c +4 -4
- 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: 989676fa7f23af91a250034ce2b63479b27f2d2bda3bf3c56983c36497fb4723
|
|
4
|
+
data.tar.gz: 5e18cd17dae7825eee333a11279503d136f74fc41b56eab2d5b4601fa15a5ba7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b4574c7f4b22644193c516ffc81f66bad89ac725ebc9ffe9903924ebb99c694647d6ab203c1961f3b0f1e4182971b79cc871877bda7e79ad6266453e8597d4cd
|
|
7
|
+
data.tar.gz: dd4aa832adacdcdcb77baa1022d04fdfe00eef0bc5dd7c3d73bda1b4355efe2770a7bd67cd7411355ca6acb75039542c7e7ebdab01e47aaa7f05b9cbc4122e9c
|
data/README.md
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
> [!IMPORTANT]
|
|
4
4
|
> PagePrint is not production-ready yet. The gem is still in active testing, especially around native packaging and platform compatibility.
|
|
5
5
|
|
|
6
|
-
|
|
7
6
|
`page_print` renders HTML strings to PDF files from Ruby using the `plutobook` library through a native C extension.
|
|
8
7
|
|
|
9
8
|
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.
|
|
@@ -13,7 +12,7 @@ It exists as a faster, simpler alternative to PDFKit and other `wkhtmltopdf`-bas
|
|
|
13
12
|
Add PagePrint to your Gemfile:
|
|
14
13
|
|
|
15
14
|
```ruby
|
|
16
|
-
gem "page_print"
|
|
15
|
+
gem "page_print"
|
|
17
16
|
```
|
|
18
17
|
|
|
19
18
|
Or install from RubyGems directly:
|
|
@@ -34,7 +33,7 @@ Render a PDF from a controller:
|
|
|
34
33
|
class PrintsController < ApplicationController
|
|
35
34
|
def pdf
|
|
36
35
|
html = render_to_string(template: "prints/pdf", formats: [:html], layout: "pdf")
|
|
37
|
-
pdf = PagePrint.
|
|
36
|
+
pdf = PagePrint.render(
|
|
38
37
|
html,
|
|
39
38
|
page_size: :a4,
|
|
40
39
|
margins: :normal,
|
|
@@ -59,7 +58,7 @@ During controller actions, PagePrint defaults `base_url` to `request.base_url`.
|
|
|
59
58
|
You can still override `base_url` explicitly:
|
|
60
59
|
|
|
61
60
|
```ruby
|
|
62
|
-
pdf = PagePrint.
|
|
61
|
+
pdf = PagePrint.render(html, base_url: "https://example.com")
|
|
63
62
|
```
|
|
64
63
|
|
|
65
64
|
Override the fetcher only when needed:
|
|
@@ -88,19 +87,19 @@ HTML
|
|
|
88
87
|
|
|
89
88
|
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
90
89
|
|
|
91
|
-
PagePrint.
|
|
90
|
+
PagePrint.render_to_file(html, output_path, base_url: "https://example.com")
|
|
92
91
|
```
|
|
93
92
|
|
|
94
93
|
To get the generated PDF as a binary string instead of writing directly to a file:
|
|
95
94
|
|
|
96
95
|
```ruby
|
|
97
|
-
pdf = PagePrint.
|
|
96
|
+
pdf = PagePrint.render(html, base_url: "https://example.com")
|
|
98
97
|
```
|
|
99
98
|
|
|
100
99
|
Use custom page dimensions and margins when a preset is not enough:
|
|
101
100
|
|
|
102
101
|
```ruby
|
|
103
|
-
pdf = PagePrint.
|
|
102
|
+
pdf = PagePrint.render(
|
|
104
103
|
html,
|
|
105
104
|
page_size: { width: 100, height: 150, unit: :mm },
|
|
106
105
|
margins: { top: 5, right: 6, bottom: 7, left: 8, unit: :mm }
|
|
@@ -145,7 +144,7 @@ RUNS=30 WARMUPS=3 bundle exec ruby benchmark/pdf_renderers.rb
|
|
|
145
144
|
Measured on 2026-05-30 with Ruby 3.4.7 on Apple Silicon:
|
|
146
145
|
|
|
147
146
|
| Renderer | Avg wall | P95 wall | Avg CPU | Avg peak RSS | Avg PDF |
|
|
148
|
-
|
|
147
|
+
| --- | ---: | ---: | ---: | ---: | ---: |
|
|
149
148
|
| `page_print` | 78.2ms | 89.6ms | 93.4ms | 42.1MB | 33.0KB |
|
|
150
149
|
| PDFKit | 782.2ms | 2127.1ms | 824.8ms | 59.4MB | 27.9KB |
|
|
151
150
|
|
|
@@ -161,7 +160,7 @@ For options and CSV output, see `benchmark/README.md`.
|
|
|
161
160
|
Supported platforms:
|
|
162
161
|
|
|
163
162
|
| Platform | Install Type |
|
|
164
|
-
|
|
163
|
+
| --- | --- |
|
|
165
164
|
| `x86_64-linux` | Vendored PlutoBook, local Ruby extension build |
|
|
166
165
|
| `arm64-darwin` | Vendored PlutoBook, local Ruby extension build |
|
|
167
166
|
| Other platforms | Source build |
|
|
@@ -182,7 +181,7 @@ Native gems bundle PlutoBook and required non-system shared libraries. Optional
|
|
|
182
181
|
|
|
183
182
|
## Notes
|
|
184
183
|
|
|
185
|
-
- The extension supports writing to a file path with `
|
|
184
|
+
- The extension supports writing to a file path with `render_to_file` or returning PDF bytes with `render`.
|
|
186
185
|
- JavaScript execution is intentionally unsupported.
|
|
187
186
|
- Native gems disable PlutoBook's optional curl, TurboJPEG, and WebP features.
|
|
188
187
|
|
|
@@ -214,13 +213,13 @@ require "tmpdir"
|
|
|
214
213
|
|
|
215
214
|
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
216
215
|
|
|
217
|
-
PagePrint.
|
|
216
|
+
PagePrint.render_to_file("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)
|
|
218
217
|
```
|
|
219
218
|
|
|
220
219
|
You can also do a quick one-shot smoke test from the shell:
|
|
221
220
|
|
|
222
221
|
```sh
|
|
223
|
-
bundle exec ruby -Ilib -e 'require "tmpdir"; require "page_print"; output_path = File.join(Dir.tmpdir, "page_print-output.pdf"); p PagePrint.
|
|
222
|
+
bundle exec ruby -Ilib -e 'require "tmpdir"; require "page_print"; output_path = File.join(Dir.tmpdir, "page_print-output.pdf"); p PagePrint.render_to_file("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)'
|
|
224
223
|
```
|
|
225
224
|
|
|
226
225
|
Or use the development console, which compiles the native extension first and then starts IRB with `PagePrint` loaded:
|
|
@@ -278,7 +277,7 @@ Build an Apple Silicon macOS platform gem with a vendored PlutoBook library:
|
|
|
278
277
|
bundle exec rake package:darwin_arm64
|
|
279
278
|
```
|
|
280
279
|
|
|
281
|
-
These tasks check out PlutoBook `v0.
|
|
280
|
+
These tasks check out PlutoBook `v0.19.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.
|
|
282
281
|
|
|
283
282
|
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.
|
|
284
283
|
|
data/ext/page_print/page_print.c
CHANGED
|
@@ -739,7 +739,7 @@ static plutobook_stream_status_t pageprint_write_pdf_string(void *closure, const
|
|
|
739
739
|
return PLUTOBOOK_STREAM_STATUS_SUCCESS;
|
|
740
740
|
}
|
|
741
741
|
|
|
742
|
-
static VALUE
|
|
742
|
+
static VALUE pageprint_render_to_file(int argc, VALUE *argv, VALUE self) {
|
|
743
743
|
VALUE html;
|
|
744
744
|
VALUE path;
|
|
745
745
|
VALUE options;
|
|
@@ -799,7 +799,7 @@ static VALUE pageprint_html_to_pdf(int argc, VALUE *argv, VALUE self) {
|
|
|
799
799
|
return Qtrue;
|
|
800
800
|
}
|
|
801
801
|
|
|
802
|
-
static VALUE
|
|
802
|
+
static VALUE pageprint_render(int argc, VALUE *argv, VALUE self) {
|
|
803
803
|
VALUE html;
|
|
804
804
|
VALUE options;
|
|
805
805
|
pageprint_pdf_string_output_t output;
|
|
@@ -888,6 +888,6 @@ void Init_page_print(void) {
|
|
|
888
888
|
id_mm = rb_intern_const("mm");
|
|
889
889
|
id_px = rb_intern_const("px");
|
|
890
890
|
|
|
891
|
-
rb_define_singleton_method(mPagePrint, "
|
|
892
|
-
rb_define_singleton_method(mPagePrint, "
|
|
891
|
+
rb_define_singleton_method(mPagePrint, "render_to_file", RUBY_METHOD_FUNC(pageprint_render_to_file), -1);
|
|
892
|
+
rb_define_singleton_method(mPagePrint, "render", RUBY_METHOD_FUNC(pageprint_render), -1);
|
|
893
893
|
}
|
data/lib/page_print/version.rb
CHANGED