page_print 0.1.8 → 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 +9 -9
- 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
|
@@ -33,7 +33,7 @@ Render a PDF from a controller:
|
|
|
33
33
|
class PrintsController < ApplicationController
|
|
34
34
|
def pdf
|
|
35
35
|
html = render_to_string(template: "prints/pdf", formats: [:html], layout: "pdf")
|
|
36
|
-
pdf = PagePrint.
|
|
36
|
+
pdf = PagePrint.render(
|
|
37
37
|
html,
|
|
38
38
|
page_size: :a4,
|
|
39
39
|
margins: :normal,
|
|
@@ -58,7 +58,7 @@ During controller actions, PagePrint defaults `base_url` to `request.base_url`.
|
|
|
58
58
|
You can still override `base_url` explicitly:
|
|
59
59
|
|
|
60
60
|
```ruby
|
|
61
|
-
pdf = PagePrint.
|
|
61
|
+
pdf = PagePrint.render(html, base_url: "https://example.com")
|
|
62
62
|
```
|
|
63
63
|
|
|
64
64
|
Override the fetcher only when needed:
|
|
@@ -87,19 +87,19 @@ HTML
|
|
|
87
87
|
|
|
88
88
|
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
89
89
|
|
|
90
|
-
PagePrint.
|
|
90
|
+
PagePrint.render_to_file(html, output_path, base_url: "https://example.com")
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
To get the generated PDF as a binary string instead of writing directly to a file:
|
|
94
94
|
|
|
95
95
|
```ruby
|
|
96
|
-
pdf = PagePrint.
|
|
96
|
+
pdf = PagePrint.render(html, base_url: "https://example.com")
|
|
97
97
|
```
|
|
98
98
|
|
|
99
99
|
Use custom page dimensions and margins when a preset is not enough:
|
|
100
100
|
|
|
101
101
|
```ruby
|
|
102
|
-
pdf = PagePrint.
|
|
102
|
+
pdf = PagePrint.render(
|
|
103
103
|
html,
|
|
104
104
|
page_size: { width: 100, height: 150, unit: :mm },
|
|
105
105
|
margins: { top: 5, right: 6, bottom: 7, left: 8, unit: :mm }
|
|
@@ -181,7 +181,7 @@ Native gems bundle PlutoBook and required non-system shared libraries. Optional
|
|
|
181
181
|
|
|
182
182
|
## Notes
|
|
183
183
|
|
|
184
|
-
- 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`.
|
|
185
185
|
- JavaScript execution is intentionally unsupported.
|
|
186
186
|
- Native gems disable PlutoBook's optional curl, TurboJPEG, and WebP features.
|
|
187
187
|
|
|
@@ -213,13 +213,13 @@ require "tmpdir"
|
|
|
213
213
|
|
|
214
214
|
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
215
215
|
|
|
216
|
-
PagePrint.
|
|
216
|
+
PagePrint.render_to_file("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)
|
|
217
217
|
```
|
|
218
218
|
|
|
219
219
|
You can also do a quick one-shot smoke test from the shell:
|
|
220
220
|
|
|
221
221
|
```sh
|
|
222
|
-
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)'
|
|
223
223
|
```
|
|
224
224
|
|
|
225
225
|
Or use the development console, which compiles the native extension first and then starts IRB with `PagePrint` loaded:
|
|
@@ -277,7 +277,7 @@ Build an Apple Silicon macOS platform gem with a vendored PlutoBook library:
|
|
|
277
277
|
bundle exec rake package:darwin_arm64
|
|
278
278
|
```
|
|
279
279
|
|
|
280
|
-
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.
|
|
281
281
|
|
|
282
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.
|
|
283
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