ferrum_pdf 3.0.0 → 3.1.0
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 +2 -0
- data/lib/ferrum_pdf/renderers.rb +19 -0
- data/lib/ferrum_pdf/version.rb +1 -1
- data/lib/ferrum_pdf.rb +10 -4
- metadata +4 -4
- data/lib/ferrum_pdf/railtie.rb +0 -25
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '09655ccad2a5a6cbf6fa1d2d2e4bb34443a0bf29501265571207079b7a689482'
|
|
4
|
+
data.tar.gz: 06f33b09c785e64e1c99dd68ef98ae2d7ea28b9460350d5d6d34e54efce3e1d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09d27b9a48ef1c126b473930e300b8ae62339404a1a7593910eae32a679106c0a9b5479d8d66ec101ca6ce7a62741665a7d350527f6990600e12181b38544c35'
|
|
7
|
+
data.tar.gz: e0d5644936b52536b70c39c96d42e7a73f4548096797bab50d076fca3dd4068fad3fa7b03c54249d87f01c3c3ca5faa03d85ba28643fff1111f38fb8dfe4a355
|
data/README.md
CHANGED
|
@@ -75,6 +75,7 @@ FerrumPdf.render_pdf(
|
|
|
75
75
|
authorize: { user: "username", password: "password" }, # Used for authenticating with basic auth
|
|
76
76
|
wait_for_idle_options: { connections: 0, duration: 0.05, timeout: 5 }, # Used for setting network wait_for_idle options
|
|
77
77
|
timeout_if_open_connections: true,
|
|
78
|
+
viewport: { width: 1200, height: 800, scale_factor: 3 } # Used for setting the viewport dimensions and device scale factor (DPR) when rendering the page
|
|
78
79
|
|
|
79
80
|
pdf_options: {
|
|
80
81
|
landscape: false, # paper orientation
|
|
@@ -190,6 +191,7 @@ FerrumPdf.configure do |config|
|
|
|
190
191
|
config.page_options.authorize = { user: "username", password: "password" }
|
|
191
192
|
config.page_options.wait_for_idle_options = { timeout: 90 }
|
|
192
193
|
config.page_options.retries = 3
|
|
194
|
+
config.page_options.viewport = { width: 1200, height: 800, scale_factor: 3 }
|
|
193
195
|
|
|
194
196
|
config.pdf_options.margin_top = 0.2
|
|
195
197
|
config.pdf_options.margin_bottom = 0.2
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
ActiveSupport.on_load(:action_controller) do
|
|
2
|
+
# render ferrum_pdf: { pdf options }, template: "whatever", disposition: :inline, filename: "example.pdf"
|
|
3
|
+
ActionController.add_renderer :ferrum_pdf do |pdf_options, options|
|
|
4
|
+
send_data_options = options.extract!(:disposition, :filename, :status)
|
|
5
|
+
url = pdf_options.delete(:url)
|
|
6
|
+
html = render_to_string(**options.with_defaults(formats: [ :html ])) if url.blank?
|
|
7
|
+
pdf = FerrumPdf.render_pdf(html: html, display_url: request.original_url, url: url, pdf_options: pdf_options)
|
|
8
|
+
send_data(pdf, **send_data_options.with_defaults(type: :pdf))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# render ferrum_screenshot: { pdf options }, template: "whatever", disposition: :inline, filename: "example.png"
|
|
12
|
+
ActionController.add_renderer :ferrum_screenshot do |screenshot_options, options|
|
|
13
|
+
send_data_options = options.extract!(:disposition, :filename, :status)
|
|
14
|
+
url = screenshot_options.delete(:url)
|
|
15
|
+
html = render_to_string(**options.with_defaults(formats: [ :html ])) if url.blank?
|
|
16
|
+
screenshot = FerrumPdf.render_screenshot(url: url, html: html, display_url: request.original_url, screenshot_options: screenshot_options)
|
|
17
|
+
send_data(screenshot, **send_data_options.with_defaults(type: screenshot_options.fetch(:format, :png)))
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/ferrum_pdf/version.rb
CHANGED
data/lib/ferrum_pdf.rb
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
require "ferrum_pdf/version"
|
|
2
|
-
require "ferrum_pdf/railtie"
|
|
3
1
|
require "ferrum"
|
|
2
|
+
require "action_controller"
|
|
3
|
+
|
|
4
|
+
require "ferrum_pdf/renderers"
|
|
5
|
+
require "ferrum_pdf/version"
|
|
4
6
|
|
|
5
7
|
module FerrumPdf
|
|
6
8
|
DEFAULT_HEADER_TEMPLATE = "<div class='date text left'></div><div class='title text center'></div>"
|
|
@@ -81,20 +83,24 @@ module FerrumPdf
|
|
|
81
83
|
end
|
|
82
84
|
end
|
|
83
85
|
|
|
86
|
+
private
|
|
87
|
+
|
|
84
88
|
# Loads page into the browser to be used for rendering PDFs or screenshots
|
|
85
89
|
#
|
|
86
|
-
def load_page(url: nil, html: nil, display_url: nil, authorize: nil, wait_for_idle_options: nil, timeout_if_open_connections:
|
|
90
|
+
def load_page(url: nil, html: nil, display_url: nil, authorize: nil, wait_for_idle_options: nil, timeout_if_open_connections: nil, browser: nil, retries: nil, viewport: nil)
|
|
87
91
|
try ||= 0
|
|
88
92
|
authorize ||= config.dig(:page_options, :authorize)
|
|
89
93
|
retries ||= config.page_options.fetch(:retries, 1)
|
|
90
94
|
wait_for_idle_options = config.page_options.fetch(:wait_for_idle_options, {}).merge(wait_for_idle_options || {})
|
|
91
|
-
timeout_if_open_connections
|
|
95
|
+
timeout_if_open_connections = config.page_options.fetch(:timeout_if_open_connections, true) if timeout_if_open_connections.nil?
|
|
96
|
+
viewport ||= config.dig(:page_options, :viewport)
|
|
92
97
|
|
|
93
98
|
with_browser(browser) do |browser|
|
|
94
99
|
# Closes page automatically after block finishes
|
|
95
100
|
# https://github.com/rubycdp/ferrum/blob/main/lib/ferrum/browser.rb#L169
|
|
96
101
|
browser.create_page do |page|
|
|
97
102
|
page.network.authorize(**authorize) { |req| req.continue } if authorize
|
|
103
|
+
page.set_viewport(**viewport) if viewport
|
|
98
104
|
|
|
99
105
|
# Load content
|
|
100
106
|
if html
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ferrum_pdf
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Chris Oliver
|
|
@@ -10,7 +10,7 @@ cert_chain: []
|
|
|
10
10
|
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: actionpack
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
16
|
- - ">="
|
|
@@ -49,7 +49,7 @@ files:
|
|
|
49
49
|
- README.md
|
|
50
50
|
- Rakefile
|
|
51
51
|
- lib/ferrum_pdf.rb
|
|
52
|
-
- lib/ferrum_pdf/
|
|
52
|
+
- lib/ferrum_pdf/renderers.rb
|
|
53
53
|
- lib/ferrum_pdf/version.rb
|
|
54
54
|
homepage: https://github.com/excid3/ferrum_pdf
|
|
55
55
|
licenses:
|
|
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
72
72
|
- !ruby/object:Gem::Version
|
|
73
73
|
version: '0'
|
|
74
74
|
requirements: []
|
|
75
|
-
rubygems_version:
|
|
75
|
+
rubygems_version: 4.0.2
|
|
76
76
|
specification_version: 4
|
|
77
77
|
summary: PDFs & screenshots for Rails using Ferrum & headless Chrome
|
|
78
78
|
test_files: []
|
data/lib/ferrum_pdf/railtie.rb
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
module FerrumPdf
|
|
2
|
-
class Railtie < ::Rails::Railtie
|
|
3
|
-
initializer "ferrum_pdf.controller" do
|
|
4
|
-
ActiveSupport.on_load(:action_controller) do
|
|
5
|
-
# render ferrum_pdf: { pdf options }, template: "whatever", disposition: :inline, filename: "example.pdf"
|
|
6
|
-
ActionController.add_renderer :ferrum_pdf do |pdf_options, options|
|
|
7
|
-
send_data_options = options.extract!(:disposition, :filename, :status)
|
|
8
|
-
url = pdf_options.delete(:url)
|
|
9
|
-
html = render_to_string(**options.with_defaults(formats: [ :html ])) if url.blank?
|
|
10
|
-
pdf = FerrumPdf.render_pdf(html: html, display_url: request.original_url, url: url, pdf_options: pdf_options)
|
|
11
|
-
send_data(pdf, **send_data_options.with_defaults(type: :pdf))
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
# render ferrum_screenshot: { pdf options }, template: "whatever", disposition: :inline, filename: "example.png"
|
|
15
|
-
ActionController.add_renderer :ferrum_screenshot do |screenshot_options, options|
|
|
16
|
-
send_data_options = options.extract!(:disposition, :filename, :status)
|
|
17
|
-
url = screenshot_options.delete(:url)
|
|
18
|
-
html = render_to_string(**options.with_defaults(formats: [ :html ])) if url.blank?
|
|
19
|
-
screenshot = FerrumPdf.render_screenshot(url: url, html: html, display_url: request.original_url, screenshot_options: screenshot_options)
|
|
20
|
-
send_data(screenshot, **send_data_options.with_defaults(type: screenshot_options.fetch(:format, :png)))
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|