page_print 0.1.1-arm64-darwin
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 +7 -0
- data/LICENSE +21 -0
- data/README.md +247 -0
- data/ext/page_print/extconf.rb +48 -0
- data/ext/page_print/page_print.c +851 -0
- data/lib/page_print/page_print.bundle +0 -0
- data/lib/page_print/rails_resource_fetcher.rb +138 -0
- data/lib/page_print/railtie.rb +15 -0
- data/lib/page_print/vendor/arm64-darwin/include/plutobook/plutobook.h +1101 -0
- data/lib/page_print/vendor/arm64-darwin/include/plutobook/plutobook.hpp +1361 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libX11.6.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libXau.6.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libXdmcp.6.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libXext.6.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libXrender.1.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libcairo.2.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libfontconfig.1.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libfreetype.6.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libglib-2.0.0.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libgraphite2.3.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libharfbuzz.0.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libicudata.78.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libicui18n.78.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libicuuc.78.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libintl.8.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libpcre2-8.0.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libpixman-1.0.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libplutobook.0.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libplutobook.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libpng16.16.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libxcb-render.0.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libxcb-shm.0.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/libxcb.1.dylib +0 -0
- data/lib/page_print/vendor/arm64-darwin/lib/pkgconfig/plutobook.pc +10 -0
- data/lib/page_print/version.rb +3 -0
- data/lib/page_print.rb +28 -0
- metadata +79 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: f1eaf3500d56f56b9eee208cb6600c815ac97ca92089a892c8c1fced4f29de95
|
|
4
|
+
data.tar.gz: 81d56eca9a927445ee5173b617e82ded78a379c6e07a2141c71daeddc586b0a3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 95151debb73305f8b8bf853d5beb1cfb9c97bbce1708a036410a0316fac9a6c9b99c7990865c2731650a27d69b10d48582b6ffdf1c21cf37270e2bc8fac70645
|
|
7
|
+
data.tar.gz: 59e951ac436ca402fc83651405fa576429ba1f11fe67f5a8f03a91b1bce648e69a6c7da94462b2d14e3bf6c500c7e764d1ace6e7c42fd8d51e5a80350669c95f
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Dino Maric
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# PagePrint
|
|
2
|
+
|
|
3
|
+
`page_print` is a Ruby gem with a native C extension that renders HTML strings to PDF files using the `plutobook` library.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Ruby 3.0+
|
|
8
|
+
- Native gems are published for `x86_64-linux` and `arm64-darwin`.
|
|
9
|
+
- Source builds on unsupported platforms require PlutoBook development headers and library files.
|
|
10
|
+
|
|
11
|
+
### Source Build Requirements
|
|
12
|
+
|
|
13
|
+
On macOS with Homebrew:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
brew install plutobook pkg-config
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
If `pkg-config` cannot find `plutobook`, install the gem with explicit include and library paths:
|
|
20
|
+
|
|
21
|
+
```sh
|
|
22
|
+
gem install page_print -- --with-plutobook-include=/path/to/include --with-plutobook-lib=/path/to/lib
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
|
+
Add PagePrint to your Gemfile:
|
|
28
|
+
|
|
29
|
+
```ruby
|
|
30
|
+
gem "page_print", "~> 0.1.1"
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or install from RubyGems directly:
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
gem install page_print
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
The 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.
|
|
40
|
+
|
|
41
|
+
## Supported Platforms
|
|
42
|
+
|
|
43
|
+
| Platform | Install Type |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `x86_64-linux` | Native gem |
|
|
46
|
+
| `arm64-darwin` | Native gem |
|
|
47
|
+
| Other platforms | Source build |
|
|
48
|
+
|
|
49
|
+
## Local Build
|
|
50
|
+
|
|
51
|
+
Build and install locally:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
gem build page_print.gemspec
|
|
55
|
+
gem install ./page_print-*.gem
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Development
|
|
59
|
+
|
|
60
|
+
1. Install development dependencies:
|
|
61
|
+
|
|
62
|
+
```sh
|
|
63
|
+
bundle install
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
2. Compile the native extension into `lib/page_print`:
|
|
67
|
+
|
|
68
|
+
```sh
|
|
69
|
+
bundle exec rake compile
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
3. Open an interactive Ruby session against the local checkout:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
bundle exec irb -Ilib
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Then load the gem from the repo and try it:
|
|
79
|
+
|
|
80
|
+
```ruby
|
|
81
|
+
require "page_print"
|
|
82
|
+
require "tmpdir"
|
|
83
|
+
|
|
84
|
+
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
85
|
+
|
|
86
|
+
PagePrint.html_to_pdf("<html><body><h1>Hello</h1></body></html>", output_path, page_size: :letter, margins: :narrow, media: :screen)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
You can also do a quick one-shot smoke test from the shell:
|
|
90
|
+
|
|
91
|
+
```sh
|
|
92
|
+
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)'
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Or use the development console, which compiles the native extension first and then starts IRB with `PagePrint` loaded:
|
|
96
|
+
|
|
97
|
+
```sh
|
|
98
|
+
bin/console
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Running Tests
|
|
102
|
+
|
|
103
|
+
Run the test suite only:
|
|
104
|
+
|
|
105
|
+
```sh
|
|
106
|
+
bundle exec rake test
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
Or run the default rake task, which compiles the extension and then runs tests:
|
|
110
|
+
|
|
111
|
+
```sh
|
|
112
|
+
bundle exec rake
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Building Native Gems
|
|
116
|
+
|
|
117
|
+
Build an `x86_64-linux` platform gem with a vendored PlutoBook library:
|
|
118
|
+
|
|
119
|
+
```sh
|
|
120
|
+
bundle exec rake package:linux
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Build an Apple Silicon macOS platform gem with a vendored PlutoBook library:
|
|
124
|
+
|
|
125
|
+
```sh
|
|
126
|
+
bundle exec rake package:darwin_arm64
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
These tasks check out PlutoBook `v0.17.0`, build it into `lib/page_print/vendor/<platform>`, compile the PagePrint native extension against that vendored build, and write a platform gem to `pkg/`.
|
|
130
|
+
|
|
131
|
+
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.
|
|
132
|
+
|
|
133
|
+
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.
|
|
134
|
+
|
|
135
|
+
## Rails Usage
|
|
136
|
+
|
|
137
|
+
PagePrint is currently 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`.
|
|
138
|
+
|
|
139
|
+
Render a PDF from a controller:
|
|
140
|
+
|
|
141
|
+
```ruby
|
|
142
|
+
class PrintsController < ApplicationController
|
|
143
|
+
def pdf
|
|
144
|
+
html = render_to_string(template: "prints/pdf", formats: [:html], layout: "pdf")
|
|
145
|
+
pdf = PagePrint.html_to_pdf_string(
|
|
146
|
+
html,
|
|
147
|
+
page_size: :a4,
|
|
148
|
+
margins: :normal,
|
|
149
|
+
media: :print,
|
|
150
|
+
metadata: { title: "Print PDF", author: "PagePrint" }
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
send_data pdf, filename: "print.pdf", type: "application/pdf", disposition: "inline"
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Use normal Rails asset helpers in the PDF template or layout:
|
|
159
|
+
|
|
160
|
+
```erb
|
|
161
|
+
<%= stylesheet_link_tag "pdf" %>
|
|
162
|
+
<%= image_tag "logo.png" %>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
During controller actions, PagePrint defaults `base_url` to `request.base_url`. The default Rails resource fetcher resolves `/assets/...` through Propshaft or `public/assets`, avoiding HTTP requests back to the Rails app.
|
|
166
|
+
|
|
167
|
+
You can still override `base_url` explicitly:
|
|
168
|
+
|
|
169
|
+
```ruby
|
|
170
|
+
pdf = PagePrint.html_to_pdf_string(html, base_url: "https://example.com")
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Override the fetcher only when needed:
|
|
174
|
+
|
|
175
|
+
```ruby
|
|
176
|
+
# config/initializers/page_print.rb
|
|
177
|
+
PagePrint.configure do |config|
|
|
178
|
+
config.resource_fetcher = MyResourceFetcher.new
|
|
179
|
+
end
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## Ruby Usage
|
|
183
|
+
|
|
184
|
+
```ruby
|
|
185
|
+
require "page_print"
|
|
186
|
+
require "tmpdir"
|
|
187
|
+
|
|
188
|
+
html = <<~HTML
|
|
189
|
+
<html>
|
|
190
|
+
<body>
|
|
191
|
+
<h1>Hello</h1>
|
|
192
|
+
<p>This PDF was generated by PagePrint.</p>
|
|
193
|
+
</body>
|
|
194
|
+
</html>
|
|
195
|
+
HTML
|
|
196
|
+
|
|
197
|
+
output_path = File.join(Dir.tmpdir, "page_print-output.pdf")
|
|
198
|
+
|
|
199
|
+
PagePrint.html_to_pdf(html, output_path, base_url: "https://example.com")
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
To get the generated PDF as a binary string instead of writing directly to a file:
|
|
203
|
+
|
|
204
|
+
```ruby
|
|
205
|
+
pdf = PagePrint.html_to_pdf_string(html, base_url: "https://example.com")
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Use custom page dimensions and margins when a preset is not enough:
|
|
209
|
+
|
|
210
|
+
```ruby
|
|
211
|
+
pdf = PagePrint.html_to_pdf_string(
|
|
212
|
+
html,
|
|
213
|
+
page_size: { width: 100, height: 150, unit: :mm },
|
|
214
|
+
margins: { top: 5, right: 6, bottom: 7, left: 8, unit: :mm }
|
|
215
|
+
)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
You can configure default options once, for example to provide a resource fetcher used by all renders:
|
|
219
|
+
|
|
220
|
+
```ruby
|
|
221
|
+
PagePrint.configure do |config|
|
|
222
|
+
config.resource_fetcher = lambda do |url|
|
|
223
|
+
next unless url == "asset:pdf.css"
|
|
224
|
+
|
|
225
|
+
{ content: "body { font-family: sans-serif; }", mime_type: "text/css" }
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Supported keyword options:
|
|
231
|
+
|
|
232
|
+
- `base_url:` string used to resolve relative URLs in the HTML
|
|
233
|
+
- `page_size:` one of `:a3`, `:a4`, `:a5`, `:b4`, `:b5`, `:letter`, `:legal`, `:ledger`, or `{ width:, height:, unit: }`
|
|
234
|
+
- `margins:` one of `:none`, `:normal`, `:narrow`, `:moderate`, `:wide`, or `{ top:, right:, bottom:, left:, unit: }`
|
|
235
|
+
- `media:` one of `:print`, `:screen`
|
|
236
|
+
- `resource_fetcher:` callable that receives a URL and returns `nil` or `{ content:, mime_type:, text_encoding: nil }`
|
|
237
|
+
- `metadata:` hash with `:title`, `:author`, `:subject`, `:keywords`, `:creation_date`, or `:modification_date`
|
|
238
|
+
|
|
239
|
+
`metadata[:creation_date]` and `metadata[:modification_date]` should be ISO-8601 strings, for example `2026-05-10T12:00:00Z`.
|
|
240
|
+
|
|
241
|
+
Custom dimensions and margins require `unit:`. Supported units are `:pt`, `:pc`, `:in`, `:cm`, `:mm`, and `:px`.
|
|
242
|
+
|
|
243
|
+
## Notes
|
|
244
|
+
|
|
245
|
+
- The extension supports writing to a file path with `html_to_pdf` or returning PDF bytes with `html_to_pdf_string`.
|
|
246
|
+
- JavaScript execution is intentionally unsupported.
|
|
247
|
+
- Native gems disable PlutoBook's optional curl, TurboJPEG, and WebP features.
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'mkmf'
|
|
2
|
+
|
|
3
|
+
def page_print_native_platform
|
|
4
|
+
platform = Gem::Platform.local
|
|
5
|
+
|
|
6
|
+
if platform.os == 'linux' && platform.cpu == 'x86_64'
|
|
7
|
+
'x86_64-linux'
|
|
8
|
+
else
|
|
9
|
+
platform.to_s
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
project_root = File.expand_path('../..', __dir__)
|
|
14
|
+
vendor_platform = ENV.fetch('PAGE_PRINT_VENDOR_PLATFORM', page_print_native_platform)
|
|
15
|
+
vendor_dir = File.join(project_root, 'lib', 'page_print', 'vendor', vendor_platform)
|
|
16
|
+
vendor_include_dir = File.join(vendor_dir, 'include')
|
|
17
|
+
vendor_lib_dir = File.join(vendor_dir, 'lib')
|
|
18
|
+
|
|
19
|
+
if File.directory?(vendor_include_dir) && File.directory?(vendor_lib_dir)
|
|
20
|
+
dir_config('plutobook', vendor_include_dir, vendor_lib_dir)
|
|
21
|
+
|
|
22
|
+
if vendor_platform.end_with?('-linux')
|
|
23
|
+
$LDFLAGS = "-Wl,-rpath,\\$$ORIGIN/vendor/#{vendor_platform}/lib #{$LDFLAGS}"
|
|
24
|
+
elsif vendor_platform.end_with?('-darwin')
|
|
25
|
+
$LDFLAGS = "-Wl,-rpath,@loader_path/vendor/#{vendor_platform}/lib #{$LDFLAGS}"
|
|
26
|
+
end
|
|
27
|
+
else
|
|
28
|
+
pkg_config('plutobook')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
dir_config('plutobook')
|
|
32
|
+
|
|
33
|
+
['/opt/homebrew/opt/plutobook', '/usr/local/opt/plutobook'].each do |prefix|
|
|
34
|
+
next unless File.directory?(prefix)
|
|
35
|
+
|
|
36
|
+
dir_config('plutobook', File.join(prefix, 'include'), File.join(prefix, 'lib'))
|
|
37
|
+
break
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
unless have_header('plutobook/plutobook.h')
|
|
41
|
+
abort 'plutobook header not found. Install plutobook or pass --with-plutobook-include=/path/to/include'
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
unless have_library('plutobook', 'plutobook_create')
|
|
45
|
+
abort 'plutobook library not found. Install plutobook or pass --with-plutobook-lib=/path/to/lib'
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
create_makefile('page_print/page_print')
|