page_print 0.1.3 → 0.1.6
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 +153 -116
- data/ext/page_print/page_print.c +70 -28
- data/lib/page_print/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 169eff31f74498423a1a2e143966ade6f58e912a548922f906fba8b64264e905
|
|
4
|
+
data.tar.gz: 61a523b3f98cd4b36cdcd4b9fce35fa011995ef37a431a0b6379fa15e05a24c4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 703a44815c6a315aabf6bafd7e8f2f355794f619689ed5b37b31b58ba83388176da9ddde484484c818fb9ebc13132e5b62cbe32613f72776c778cb500406be88
|
|
7
|
+
data.tar.gz: 80a783772bd1ff36397aa6c830dd80373697664cd4a9d0e36a7d4798a87c906bf28683cca854b07f6edfd080b91fd5956d49cae22e35e9d2e04860f62c244b9a
|
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
|
|
@@ -237,12 +130,156 @@ Supported keyword options:
|
|
|
237
130
|
- `resource_fetcher:` callable that receives a URL and returns `nil` or `{ content:, mime_type:, text_encoding: nil }`
|
|
238
131
|
- `metadata:` hash with `:title`, `:author`, `:subject`, `:keywords`, `:creation_date`, or `:modification_date`
|
|
239
132
|
|
|
133
|
+
Unresolved URLs are not fetched over the network. Provide assets through `resource_fetcher`, or return `nil` to skip a URL.
|
|
134
|
+
|
|
240
135
|
`metadata[:creation_date]` and `metadata[:modification_date]` should be ISO-8601 strings, for example `2026-05-10T12:00:00Z`.
|
|
241
136
|
|
|
242
137
|
Custom dimensions and margins require `unit:`. Supported units are `:pt`, `:pc`, `:in`, `:cm`, `:mm`, and `:px`.
|
|
243
138
|
|
|
139
|
+
## Benchmarking
|
|
140
|
+
|
|
141
|
+
```sh
|
|
142
|
+
RUNS=30 WARMUPS=3 bundle exec ruby benchmark/pdf_renderers.rb
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Measured on 2026-05-30 with Ruby 3.4.7 on Apple Silicon:
|
|
146
|
+
|
|
147
|
+
| Renderer | Avg wall | P95 wall | Avg CPU | Avg peak RSS | Avg PDF |
|
|
148
|
+
|---|---:|---:|---:|---:|---:|
|
|
149
|
+
| `page_print` | 78.2ms | 89.6ms | 93.4ms | 42.1MB | 33.0KB |
|
|
150
|
+
| PDFKit | 782.2ms | 2127.1ms | 824.8ms | 59.4MB | 27.9KB |
|
|
151
|
+
|
|
152
|
+
For options and CSV output, see `benchmark/README.md`.
|
|
153
|
+
|
|
154
|
+
## Requirements
|
|
155
|
+
|
|
156
|
+
- Ruby 3.2+
|
|
157
|
+
- Native gems are published for `x86_64-linux` and `arm64-darwin`.
|
|
158
|
+
- Native gems vendor PlutoBook but compile the small Ruby extension during install so it links against your local Ruby.
|
|
159
|
+
- Source builds on unsupported platforms require PlutoBook development headers and library files.
|
|
160
|
+
|
|
161
|
+
Supported platforms:
|
|
162
|
+
|
|
163
|
+
| Platform | Install Type |
|
|
164
|
+
|---|---|
|
|
165
|
+
| `x86_64-linux` | Vendored PlutoBook, local Ruby extension build |
|
|
166
|
+
| `arm64-darwin` | Vendored PlutoBook, local Ruby extension build |
|
|
167
|
+
| Other platforms | Source build |
|
|
168
|
+
|
|
169
|
+
Source build requirements on macOS with Homebrew:
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
brew install plutobook pkg-config
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
If `pkg-config` cannot find `plutobook`, install the gem with explicit include and library paths:
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
gem install page_print -- --with-plutobook-include=/path/to/include --with-plutobook-lib=/path/to/lib
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
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.
|
|
182
|
+
|
|
244
183
|
## Notes
|
|
245
184
|
|
|
246
185
|
- The extension supports writing to a file path with `html_to_pdf` or returning PDF bytes with `html_to_pdf_string`.
|
|
247
186
|
- JavaScript execution is intentionally unsupported.
|
|
248
187
|
- Native gems disable PlutoBook's optional curl, TurboJPEG, and WebP features.
|
|
188
|
+
|
|
189
|
+
## Development
|
|
190
|
+
|
|
191
|
+
Install development dependencies:
|
|
192
|
+
|
|
193
|
+
```sh
|
|
194
|
+
bundle install
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Compile the native extension into `lib/page_print`:
|
|
198
|
+
|
|
199
|
+
```sh
|
|
200
|
+
bundle exec rake compile
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
Open an interactive Ruby session against the local checkout:
|
|
204
|
+
|
|
205
|
+
```sh
|
|
206
|
+
bundle exec irb -Ilib
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
Then load the gem from the repo and try it:
|
|
210
|
+
|
|
211
|
+
```ruby
|
|
212
|
+
require "page_print"
|
|
213
|
+
require "tmpdir"
|
|
214
|
+
|
|
215
|
+
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
216
|
+
|
|
217
|
+
PagePrint.html_to_pdf("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
You can also do a quick one-shot smoke test from the shell:
|
|
221
|
+
|
|
222
|
+
```sh
|
|
223
|
+
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)'
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Or use the development console, which compiles the native extension first and then starts IRB with `PagePrint` loaded:
|
|
227
|
+
|
|
228
|
+
```sh
|
|
229
|
+
bin/console
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Running Tests
|
|
233
|
+
|
|
234
|
+
Run the test suite only:
|
|
235
|
+
|
|
236
|
+
```sh
|
|
237
|
+
bundle exec rake test
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Or run the default rake task, which compiles the extension and then runs tests:
|
|
241
|
+
|
|
242
|
+
```sh
|
|
243
|
+
bundle exec rake
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Local Build
|
|
247
|
+
|
|
248
|
+
Build and install locally:
|
|
249
|
+
|
|
250
|
+
```sh
|
|
251
|
+
gem build page_print.gemspec
|
|
252
|
+
gem install ./page_print-*.gem
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Releasing
|
|
256
|
+
|
|
257
|
+
Publish a new version with:
|
|
258
|
+
|
|
259
|
+
```sh
|
|
260
|
+
bin/bump 0.1.6
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
That updates `lib/page_print/version.rb` and `Gemfile.lock`, commits `Release 0.1.6`, creates annotated tag `v0.1.6`, and pushes `main` plus the tag. Requires a clean worktree on `main`.
|
|
264
|
+
|
|
265
|
+
The Package workflow then builds the source and platform gems, pushes them to RubyGems (trusted publishing / OIDC, GitHub environment `release`), and creates a GitHub Release with the gem artifacts and commit notes since the previous `v*` tag.
|
|
266
|
+
|
|
267
|
+
## Building Native Gems
|
|
268
|
+
|
|
269
|
+
Build an `x86_64-linux` platform gem with a vendored PlutoBook library:
|
|
270
|
+
|
|
271
|
+
```sh
|
|
272
|
+
bundle exec rake package:linux
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
Build an Apple Silicon macOS platform gem with a vendored PlutoBook library:
|
|
276
|
+
|
|
277
|
+
```sh
|
|
278
|
+
bundle exec rake package:darwin_arm64
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
These tasks check out PlutoBook `v0.18.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
|
+
|
|
283
|
+
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
|
+
|
|
285
|
+
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/ext/page_print/page_print.c
CHANGED
|
@@ -48,7 +48,7 @@ typedef struct {
|
|
|
48
48
|
plutobook_page_size_t page_size;
|
|
49
49
|
plutobook_page_margins_t margins;
|
|
50
50
|
plutobook_media_type_t media;
|
|
51
|
-
|
|
51
|
+
VALUE base_url;
|
|
52
52
|
VALUE resource_fetcher;
|
|
53
53
|
VALUE metadata;
|
|
54
54
|
} pageprint_options_t;
|
|
@@ -97,6 +97,11 @@ typedef struct {
|
|
|
97
97
|
int ok;
|
|
98
98
|
} pageprint_write_pdf_stream_args_t;
|
|
99
99
|
|
|
100
|
+
typedef struct {
|
|
101
|
+
plutobook_t *book;
|
|
102
|
+
VALUE metadata;
|
|
103
|
+
} pageprint_apply_metadata_args_t;
|
|
104
|
+
|
|
100
105
|
static VALUE pageprint_append_pdf_string(VALUE value);
|
|
101
106
|
static plutobook_stream_status_t pageprint_write_pdf_string(void *closure, const char *data, unsigned int length);
|
|
102
107
|
static plutobook_resource_data_t *pageprint_fetch_resource(void *closure, const char *url);
|
|
@@ -368,6 +373,15 @@ static void pageprint_apply_metadata(plutobook_t *book, VALUE metadata)
|
|
|
368
373
|
pageprint_set_metadata_value(book, metadata, id_modification_date, PLUTOBOOK_PDF_METADATA_MODIFICATION_DATE);
|
|
369
374
|
}
|
|
370
375
|
|
|
376
|
+
static VALUE pageprint_apply_metadata_with_gvl(VALUE ptr)
|
|
377
|
+
{
|
|
378
|
+
pageprint_apply_metadata_args_t *args = (pageprint_apply_metadata_args_t *)ptr;
|
|
379
|
+
|
|
380
|
+
pageprint_apply_metadata(args->book, args->metadata);
|
|
381
|
+
|
|
382
|
+
return Qnil;
|
|
383
|
+
}
|
|
384
|
+
|
|
371
385
|
static void *pageprint_load_html_without_gvl(void *ptr)
|
|
372
386
|
{
|
|
373
387
|
pageprint_load_html_args_t *args = ptr;
|
|
@@ -487,23 +501,26 @@ static plutobook_resource_data_t *pageprint_fetch_resource(void *closure, const
|
|
|
487
501
|
pageprint_resource_fetch_args_t args;
|
|
488
502
|
int state;
|
|
489
503
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
504
|
+
if (!NIL_P(fetcher->object)) {
|
|
505
|
+
args.fetcher = fetcher;
|
|
506
|
+
args.url = url;
|
|
507
|
+
args.resource = NULL;
|
|
493
508
|
|
|
494
|
-
|
|
509
|
+
state = (int)(intptr_t)rb_thread_call_with_gvl(pageprint_call_resource_fetcher_with_gvl, &args);
|
|
495
510
|
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
511
|
+
if (state) {
|
|
512
|
+
fetcher->state = state;
|
|
513
|
+
plutobook_set_error_message("failed to fetch URL '%s'", url);
|
|
514
|
+
return NULL;
|
|
515
|
+
}
|
|
501
516
|
|
|
502
|
-
|
|
503
|
-
|
|
517
|
+
if (args.resource) {
|
|
518
|
+
return args.resource;
|
|
519
|
+
}
|
|
504
520
|
}
|
|
505
521
|
|
|
506
|
-
|
|
522
|
+
plutobook_set_error_message("network fetch disabled for URL '%s'", url);
|
|
523
|
+
return NULL;
|
|
507
524
|
}
|
|
508
525
|
|
|
509
526
|
static pageprint_options_t pageprint_options_from_value(VALUE options)
|
|
@@ -521,7 +538,7 @@ static pageprint_options_t pageprint_options_from_value(VALUE options)
|
|
|
521
538
|
result.page_size = PLUTOBOOK_PAGE_SIZE_A4;
|
|
522
539
|
result.margins = PLUTOBOOK_PAGE_MARGINS_NORMAL;
|
|
523
540
|
result.media = PLUTOBOOK_MEDIA_TYPE_PRINT;
|
|
524
|
-
result.base_url =
|
|
541
|
+
result.base_url = Qnil;
|
|
525
542
|
result.resource_fetcher = Qnil;
|
|
526
543
|
result.metadata = Qnil;
|
|
527
544
|
|
|
@@ -556,7 +573,7 @@ static pageprint_options_t pageprint_options_from_value(VALUE options)
|
|
|
556
573
|
rb_raise(rb_eTypeError, "base_url must be a String or nil");
|
|
557
574
|
}
|
|
558
575
|
|
|
559
|
-
result.base_url =
|
|
576
|
+
result.base_url = base_url_value;
|
|
560
577
|
}
|
|
561
578
|
|
|
562
579
|
if (page_size_value != Qundef) {
|
|
@@ -596,6 +613,7 @@ static plutobook_t *pageprint_create_book_from_html(VALUE html, VALUE options, p
|
|
|
596
613
|
pageprint_options_t pageprint_options;
|
|
597
614
|
|
|
598
615
|
const char *html_str;
|
|
616
|
+
const char *base_url_str;
|
|
599
617
|
long html_len;
|
|
600
618
|
|
|
601
619
|
plutobook_t *book;
|
|
@@ -628,21 +646,30 @@ static plutobook_t *pageprint_create_book_from_html(VALUE html, VALUE options, p
|
|
|
628
646
|
resource_fetcher->object = pageprint_options.resource_fetcher;
|
|
629
647
|
resource_fetcher->state = 0;
|
|
630
648
|
|
|
631
|
-
|
|
632
|
-
plutobook_set_custom_resource_fetcher(book, pageprint_fetch_resource, resource_fetcher);
|
|
633
|
-
}
|
|
649
|
+
plutobook_set_custom_resource_fetcher(book, pageprint_fetch_resource, resource_fetcher);
|
|
634
650
|
|
|
635
651
|
/* 2. Load HTML */
|
|
636
652
|
plutobook_clear_error_message();
|
|
637
653
|
|
|
654
|
+
base_url_str = "";
|
|
655
|
+
if (!NIL_P(pageprint_options.base_url)) {
|
|
656
|
+
base_url_str = StringValueCStr(pageprint_options.base_url);
|
|
657
|
+
}
|
|
658
|
+
|
|
638
659
|
load_args.book = book;
|
|
639
660
|
load_args.html = html_str;
|
|
640
661
|
load_args.length = (int)html_len;
|
|
641
662
|
load_args.user_style = "";
|
|
642
663
|
load_args.user_script = "";
|
|
643
|
-
load_args.base_url =
|
|
664
|
+
load_args.base_url = base_url_str;
|
|
644
665
|
load_args.ok = 0;
|
|
645
666
|
|
|
667
|
+
RB_GC_GUARD(html);
|
|
668
|
+
RB_GC_GUARD(options);
|
|
669
|
+
RB_GC_GUARD(pageprint_options.base_url);
|
|
670
|
+
RB_GC_GUARD(pageprint_options.resource_fetcher);
|
|
671
|
+
RB_GC_GUARD(pageprint_options.metadata);
|
|
672
|
+
|
|
646
673
|
rb_thread_call_without_gvl(
|
|
647
674
|
pageprint_load_html_without_gvl,
|
|
648
675
|
&load_args,
|
|
@@ -665,7 +692,20 @@ static plutobook_t *pageprint_create_book_from_html(VALUE html, VALUE options, p
|
|
|
665
692
|
rb_jump_tag(resource_fetcher->state);
|
|
666
693
|
}
|
|
667
694
|
|
|
668
|
-
|
|
695
|
+
{
|
|
696
|
+
pageprint_apply_metadata_args_t metadata_args;
|
|
697
|
+
int metadata_state = 0;
|
|
698
|
+
|
|
699
|
+
metadata_args.book = book;
|
|
700
|
+
metadata_args.metadata = pageprint_options.metadata;
|
|
701
|
+
|
|
702
|
+
rb_protect(pageprint_apply_metadata_with_gvl, (VALUE)&metadata_args, &metadata_state);
|
|
703
|
+
|
|
704
|
+
if (metadata_state) {
|
|
705
|
+
plutobook_destroy(book);
|
|
706
|
+
rb_jump_tag(metadata_state);
|
|
707
|
+
}
|
|
708
|
+
}
|
|
669
709
|
|
|
670
710
|
return book;
|
|
671
711
|
}
|
|
@@ -734,6 +774,11 @@ static VALUE pageprint_html_to_pdf(int argc, VALUE *argv, VALUE self) {
|
|
|
734
774
|
write_args.path = path_str;
|
|
735
775
|
write_args.ok = 0;
|
|
736
776
|
|
|
777
|
+
RB_GC_GUARD(html);
|
|
778
|
+
RB_GC_GUARD(options);
|
|
779
|
+
RB_GC_GUARD(resource_fetcher.object);
|
|
780
|
+
RB_GC_GUARD(path);
|
|
781
|
+
|
|
737
782
|
rb_thread_call_without_gvl(
|
|
738
783
|
pageprint_write_pdf_without_gvl,
|
|
739
784
|
&write_args,
|
|
@@ -751,10 +796,6 @@ static VALUE pageprint_html_to_pdf(int argc, VALUE *argv, VALUE self) {
|
|
|
751
796
|
pageprint_raise_plutobook_error_with_path(rb_eRuntimeError, "failed to write PDF to", path_str);
|
|
752
797
|
}
|
|
753
798
|
|
|
754
|
-
RB_GC_GUARD(resource_fetcher.object);
|
|
755
|
-
RB_GC_GUARD(options);
|
|
756
|
-
RB_GC_GUARD(path);
|
|
757
|
-
|
|
758
799
|
return Qtrue;
|
|
759
800
|
}
|
|
760
801
|
|
|
@@ -783,6 +824,11 @@ static VALUE pageprint_html_to_pdf_string(int argc, VALUE *argv, VALUE self) {
|
|
|
783
824
|
write_args.output = &output;
|
|
784
825
|
write_args.ok = 0;
|
|
785
826
|
|
|
827
|
+
RB_GC_GUARD(html);
|
|
828
|
+
RB_GC_GUARD(options);
|
|
829
|
+
RB_GC_GUARD(resource_fetcher.object);
|
|
830
|
+
RB_GC_GUARD(output.output);
|
|
831
|
+
|
|
786
832
|
rb_thread_call_without_gvl(
|
|
787
833
|
pageprint_write_pdf_stream_without_gvl,
|
|
788
834
|
&write_args,
|
|
@@ -804,10 +850,6 @@ static VALUE pageprint_html_to_pdf_string(int argc, VALUE *argv, VALUE self) {
|
|
|
804
850
|
pageprint_raise_plutobook_error(rb_eRuntimeError, "failed to write PDF to string");
|
|
805
851
|
}
|
|
806
852
|
|
|
807
|
-
RB_GC_GUARD(resource_fetcher.object);
|
|
808
|
-
RB_GC_GUARD(options);
|
|
809
|
-
RB_GC_GUARD(output.output);
|
|
810
|
-
|
|
811
853
|
return output.output;
|
|
812
854
|
}
|
|
813
855
|
|
data/lib/page_print/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: page_print
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dino Maric
|
|
@@ -40,7 +40,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
40
40
|
requirements:
|
|
41
41
|
- - ">="
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: '3.
|
|
43
|
+
version: '3.2'
|
|
44
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
45
|
requirements:
|
|
46
46
|
- - ">="
|