bidi2pdf-rails 0.0.1.alpha.1 → 0.0.1.pre.alpha
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/.idea/bidi2pdf-rails.iml +6 -44
- data/.rubocop.yml +0 -3
- data/README.md +4 -31
- data/lib/bidi2pdf_rails/chromedriver_manager_singleton.rb +1 -1
- data/lib/bidi2pdf_rails/log_subscriber.rb +13 -0
- data/lib/bidi2pdf_rails/railtie.rb +45 -10
- data/lib/bidi2pdf_rails/version.rb +1 -1
- data/lib/bidi2pdf_rails.rb +20 -74
- data/lib/generators/bidi2pdf_rails/initializer_generator.rb +6 -7
- data/lib/generators/bidi2pdf_rails/templates/bidi2pdf_rails.rb.tt +28 -60
- data/spec/dummy/app/controllers/reports_controller.rb +0 -4
- data/spec/dummy/config/environments/production.rb +1 -1
- data/spec/dummy/config/initializers/bidi2pdf_rails.rb +16 -20
- data/spec/dummy/config/initializers/cors.rb +1 -1
- data/spec/dummy/config/routes.rb +0 -2
- data/spec/dummy/log/development.log +158 -12719
- data/spec/dummy/tmp/pids/server.pid +1 -1
- metadata +7 -28
- data/lib/bidi2pdf_rails/browser_console_log_subscriber.rb +0 -24
- data/lib/bidi2pdf_rails/main_log_subscriber.rb +0 -33
- data/lib/bidi2pdf_rails/network_log_subscriber.rb +0 -20
- data/lib/bidi2pdf_rails/services/html_renderer.rb +0 -33
- data/lib/bidi2pdf_rails/services/html_to_pdf_converter.rb +0 -28
- data/lib/bidi2pdf_rails/services/pdf_browser_session.rb +0 -39
- data/lib/bidi2pdf_rails/services/pdf_renderer.rb +0 -81
- data/lib/bidi2pdf_rails/services/url_to_pdf_converter.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7316e5fbdad14a0d1e622e7ee89955f20657cdbfced7f79e2c1b2861a9d93c1e
|
4
|
+
data.tar.gz: c889dae22e63576bdc3bd9cd7e9bae199bb6da39b92819fc817d3811453be663
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c740e93dfcf86b054f7d1ecc2e503f2d676c02748c8c9bd1cc8dc38fba927b8ad9710407504875f2d610c2e1494b6e5200e940310fc6a338c2bea9e4d4029eb7
|
7
|
+
data.tar.gz: 8283d5241822de3278fa9916c6be0b6842621368c1695ad3139cef86a8c6cc40c8e65d21a9eacb30805bcef99a87b72a6faa45d308ccb08682f793cf9ecb5490
|
data/.idea/bidi2pdf-rails.iml
CHANGED
@@ -200,7 +200,6 @@
|
|
200
200
|
<orderEntry type="library" scope="PROVIDED" name="websocket-client-simple (v0.9.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
|
201
201
|
<orderEntry type="library" scope="PROVIDED" name="websocket-driver (v0.7.7, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
|
202
202
|
<orderEntry type="library" scope="PROVIDED" name="websocket-extensions (v0.1.5, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
|
203
|
-
<orderEntry type="library" scope="PROVIDED" name="websocket-native (v1.0.0, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
|
204
203
|
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.7.2, RVM: ruby-3.3.4 [bidi2pdf-rails]) [gem]" level="application" />
|
205
204
|
</component>
|
206
205
|
<component name="RailsGeneratorsCache">
|
@@ -339,6 +338,9 @@
|
|
339
338
|
<entry key="config">
|
340
339
|
<value>file://$MODULE_DIR$/config</value>
|
341
340
|
</entry>
|
341
|
+
<entry key="config/cable">
|
342
|
+
<value>file://$MODULE_DIR$/config/cable.yml</value>
|
343
|
+
</entry>
|
342
344
|
<entry key="config/database">
|
343
345
|
<value>file://$MODULE_DIR$/config/database.yml</value>
|
344
346
|
</entry>
|
@@ -360,6 +362,9 @@
|
|
360
362
|
<entry key="config/routes.rb">
|
361
363
|
<value>file://$MODULE_DIR$/config/routes.rb</value>
|
362
364
|
</entry>
|
365
|
+
<entry key="config/secrets">
|
366
|
+
<value>file://$MODULE_DIR$/config</value>
|
367
|
+
</entry>
|
363
368
|
<entry key="db">
|
364
369
|
<value>file://$MODULE_DIR$/db</value>
|
365
370
|
</entry>
|
@@ -393,9 +398,6 @@
|
|
393
398
|
<entry key="public/stylesheets">
|
394
399
|
<value>file://$MODULE_DIR$/public/stylesheets</value>
|
395
400
|
</entry>
|
396
|
-
<entry key="test/mailers/previews">
|
397
|
-
<value>file://$MODULE_DIR$/test/mailers/previews</value>
|
398
|
-
</entry>
|
399
401
|
<entry key="tmp">
|
400
402
|
<value>file://$MODULE_DIR$/tmp</value>
|
401
403
|
</entry>
|
@@ -406,44 +408,4 @@
|
|
406
408
|
<value>file://$MODULE_DIR$/vendor/assets</value>
|
407
409
|
</entry>
|
408
410
|
</component>
|
409
|
-
<component name="RakeTasksCache-v2">
|
410
|
-
<option name="myRootTask">
|
411
|
-
<RakeTaskImpl id="rake">
|
412
|
-
<subtasks>
|
413
|
-
<RakeTaskImpl description="Build bidi2pdf-rails-0.0.1.pre.alpha.gem into the pkg directory" fullCommand="build" id="build" />
|
414
|
-
<RakeTaskImpl id="build">
|
415
|
-
<subtasks>
|
416
|
-
<RakeTaskImpl description="Generate SHA512 checksum of bidi2pdf-rails-0.0.1.pre.alpha.gem into the checksums directory" fullCommand="build:checksum" id="checksum" />
|
417
|
-
</subtasks>
|
418
|
-
</RakeTaskImpl>
|
419
|
-
<RakeTaskImpl description="Remove any temporary products" fullCommand="clean" id="clean" />
|
420
|
-
<RakeTaskImpl description="Remove any generated files" fullCommand="clobber" id="clobber" />
|
421
|
-
<RakeTaskImpl description="Build and install bidi2pdf-rails-0.0.1.pre.alpha.gem into system gems" fullCommand="install" id="install" />
|
422
|
-
<RakeTaskImpl id="install">
|
423
|
-
<subtasks>
|
424
|
-
<RakeTaskImpl description="Build and install bidi2pdf-rails-0.0.1.pre.alpha.gem into system gems without network access" fullCommand="install:local" id="local" />
|
425
|
-
</subtasks>
|
426
|
-
</RakeTaskImpl>
|
427
|
-
<RakeTaskImpl description="Create tag v0.0.1.pre.alpha and build and push bidi2pdf-rails-0.0.1.pre.alpha.gem to https://rubygems.org" fullCommand="release[remote]" id="release[remote]" />
|
428
|
-
<RakeTaskImpl description="Run RuboCop" fullCommand="rubocop" id="rubocop" />
|
429
|
-
<RakeTaskImpl id="rubocop">
|
430
|
-
<subtasks>
|
431
|
-
<RakeTaskImpl description="Autocorrect RuboCop offenses (only when it's safe)" fullCommand="rubocop:autocorrect" id="autocorrect" />
|
432
|
-
<RakeTaskImpl description="Autocorrect RuboCop offenses (safe and unsafe)" fullCommand="rubocop:autocorrect_all" id="autocorrect_all" />
|
433
|
-
<RakeTaskImpl description="" fullCommand="rubocop:auto_correct" id="auto_correct" />
|
434
|
-
</subtasks>
|
435
|
-
</RakeTaskImpl>
|
436
|
-
<RakeTaskImpl description="Run RSpec code examples" fullCommand="spec" id="spec" />
|
437
|
-
<RakeTaskImpl description="" fullCommand="release" id="release" />
|
438
|
-
<RakeTaskImpl id="release">
|
439
|
-
<subtasks>
|
440
|
-
<RakeTaskImpl description="" fullCommand="release:guard_clean" id="guard_clean" />
|
441
|
-
<RakeTaskImpl description="" fullCommand="release:rubygem_push" id="rubygem_push" />
|
442
|
-
<RakeTaskImpl description="" fullCommand="release:source_control_push" id="source_control_push" />
|
443
|
-
</subtasks>
|
444
|
-
</RakeTaskImpl>
|
445
|
-
</subtasks>
|
446
|
-
</RakeTaskImpl>
|
447
|
-
</option>
|
448
|
-
</component>
|
449
411
|
</module>
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -4,12 +4,11 @@
|
|
4
4
|
[](https://codeclimate.com/github/dieter-medium/bidi2pdf-rails/test_coverage)
|
5
5
|
[](https://www.codetriage.com/dieter-medium/bidi2pdf-rails)
|
6
6
|
|
7
|
+
|
7
8
|
# 📄 Bidi2pdfRails
|
8
9
|
|
9
|
-
**Bidi2pdfRails** is the official Rails integration for [Bidi2pdf](https://github.com/dieter-medium/bidi2pdf) – a
|
10
|
-
|
11
|
-
It leverages headless browsing and offers a simple, flexible interface for PDF generation directly from your Rails
|
12
|
-
application.
|
10
|
+
**Bidi2pdfRails** is the official Rails integration for [Bidi2pdf](https://github.com/dieter-medium/bidi2pdf) – a modern, browser-based solution for converting HTML to high-quality PDFs.
|
11
|
+
It leverages headless browsing and offers a simple, flexible interface for PDF generation directly from your Rails application.
|
13
12
|
|
14
13
|
> **⚠️ Note:** This project is currently **under development** and **not yet recommended for production use**.
|
15
14
|
|
@@ -30,11 +29,8 @@ Add the following lines to your `Gemfile`:
|
|
30
29
|
```ruby
|
31
30
|
gem "bidi2pdf-rails"
|
32
31
|
# As long as the gem is not published, use:
|
33
|
-
gem "bidi2pdf-rails", github: "dieter-medium/bidi2pdf
|
32
|
+
gem "bidi2pdf-rails", github: "dieter-medium/bidi2pdf", branch: "main"
|
34
33
|
gem "bidi2pdf", github: "dieter-medium/bidi2pdf", branch: "main"
|
35
|
-
|
36
|
-
# if you want a small performance boost, you can use the following:
|
37
|
-
# gem "websocket-native"
|
38
34
|
```
|
39
35
|
|
40
36
|
Then install the dependencies:
|
@@ -62,29 +58,6 @@ gem install bidi2pdf-rails
|
|
62
58
|
You can find a full example inside the [`spec/dummy`](spec/dummy) directory of this repository.
|
63
59
|
This demonstrates how to use `Bidi2pdfRails` in a realistic mini Rails application setup.
|
64
60
|
|
65
|
-
### Basic Usage
|
66
|
-
|
67
|
-
```ruby
|
68
|
-
# Render html via controller action `render_to_string`
|
69
|
-
# Any controller action:
|
70
|
-
def show
|
71
|
-
render pdf: "invoice",
|
72
|
-
template: "invoices/show",
|
73
|
-
layout: "pdf",
|
74
|
-
locals: { invoice: @invoice },
|
75
|
-
print_options: { landscape: true },
|
76
|
-
wait_for_network_idle: true,
|
77
|
-
asset_host: "https://assets.example.com"
|
78
|
-
end
|
79
|
-
|
80
|
-
# Render pdf via direct url call
|
81
|
-
def show
|
82
|
-
# See: PdfRenderer for all options
|
83
|
-
render pdf: 'remote-report', url: "http://example.com", wait_for_page_loaded: false, print_options: { page: { format: :A4 } }
|
84
|
-
end
|
85
|
-
|
86
|
-
```
|
87
|
-
|
88
61
|
---
|
89
62
|
|
90
63
|
## 🙌 Contributing
|
@@ -16,7 +16,7 @@ module Bidi2pdfRails
|
|
16
16
|
|
17
17
|
Bidi2pdfRails.logger.info "Initializing Bidi2pdf #{msg}"
|
18
18
|
|
19
|
-
if Bidi2pdfRails.
|
19
|
+
if Bidi2pdfRails.remote_browser_url
|
20
20
|
@session = Bidi::Session.new(
|
21
21
|
session_url: Bidi2pdfRails.remote_browser_url,
|
22
22
|
headless: Bidi2pdfRails.headless,
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Bidi2pdfRails
|
4
|
+
class LogSubscriber < ActiveSupport::LogSubscriber
|
5
|
+
include Bidi2pdf::Notifications::LoggingSubscriberActions
|
6
|
+
|
7
|
+
def logger
|
8
|
+
Bidi2pdf::VerboseLogger.new(super.tagged("bidi2pdf_rails"), Bidi2pdfRails.verbosity)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
Bidi2pdfRails::LogSubscriber.attach_to "bidi2pdf", inherit_all: true
|
@@ -1,11 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "services/html_renderer"
|
4
|
-
require_relative "services/pdf_renderer"
|
5
|
-
require_relative "services/pdf_browser_session"
|
6
|
-
require_relative "services/url_to_pdf_converter"
|
7
|
-
require_relative "services/html_to_pdf_converter"
|
8
|
-
|
9
3
|
module Bidi2pdfRails
|
10
4
|
class Railtie < ::Rails::Railtie
|
11
5
|
initializer "bidi2pdf_rails.add_mime_type" do
|
@@ -15,8 +9,7 @@ module Bidi2pdfRails
|
|
15
9
|
initializer "bidi2pdf_rails.initialize_chromedriver_manager", after: :load_config_initializers do
|
16
10
|
Bidi2pdfRails.apply_bidi2pdf_config
|
17
11
|
|
18
|
-
|
19
|
-
ActiveSupport.on_load(:action_controller_base) do
|
12
|
+
Rails.application.config.after_initialize do
|
20
13
|
ChromedriverManagerSingleton.initialize_manager
|
21
14
|
end
|
22
15
|
end
|
@@ -30,14 +23,56 @@ module Bidi2pdfRails
|
|
30
23
|
|
31
24
|
initializer "bidi2pdf_rails.add_pdf_renderer" do
|
32
25
|
ActionController::Renderers.add :pdf do |filename, options|
|
26
|
+
pdf_data = ""
|
33
27
|
options = options.dup
|
34
28
|
|
35
|
-
|
29
|
+
original_asset_host = ActionController::Base.asset_host
|
30
|
+
|
31
|
+
if options[:asset_host]
|
32
|
+
ActionController::Base.asset_host = options[:asset_host]
|
33
|
+
elsif !Rails.application.config.action_controller.asset_host
|
34
|
+
# Use request base URL as fallback if no asset host configured
|
35
|
+
ActionController::Base.asset_host = request.base_url
|
36
|
+
end
|
37
|
+
|
38
|
+
html = render_to_string(options.merge(formats: [ :html ]))
|
39
|
+
|
40
|
+
Bidi2pdf.default_timeout = 30
|
41
|
+
|
42
|
+
# without a thread, the app will be blocked in dev mode
|
43
|
+
thread = Thread.new {
|
44
|
+
Rails.application.executor.wrap do
|
45
|
+
# subscriptions in other threads will not be inherited
|
46
|
+
Bidi2pdfRails::LogSubscriber.attach_to "bidi2pdf", inherit_all: true
|
47
|
+
|
48
|
+
browser = ChromedriverManagerSingleton.session.browser
|
49
|
+
context = browser.create_user_context
|
50
|
+
window = context.create_browser_window
|
51
|
+
tab = window.create_browser_tab
|
36
52
|
|
37
|
-
|
53
|
+
tab.render_html_content html
|
54
|
+
|
55
|
+
tab.wait_until_network_idle
|
56
|
+
|
57
|
+
tab.wait_until_page_loaded
|
58
|
+
|
59
|
+
pdf_data = tab.print
|
60
|
+
ensure
|
61
|
+
tab&.close
|
62
|
+
window&.close
|
63
|
+
context&.close
|
64
|
+
end
|
65
|
+
}
|
66
|
+
|
67
|
+
thread.join
|
68
|
+
|
69
|
+
send_data Base64.decode64(pdf_data),
|
38
70
|
type: Mime[:pdf],
|
39
71
|
filename: "#{filename}.pdf",
|
40
72
|
disposition: options.fetch(:disposition, "inline")
|
73
|
+
ensure
|
74
|
+
|
75
|
+
ActionController::Base.asset_host = original_asset_host
|
41
76
|
end
|
42
77
|
end
|
43
78
|
end
|
data/lib/bidi2pdf_rails.rb
CHANGED
@@ -1,71 +1,27 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "bidi2pdf"
|
4
|
-
require "
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
require_relative "bidi2pdf_rails/main_log_subscriber"
|
9
|
-
require_relative "bidi2pdf_rails/browser_console_log_subscriber"
|
10
|
-
require_relative "bidi2pdf_rails/network_log_subscriber"
|
4
|
+
require "bidi2pdf_rails/version"
|
5
|
+
require "bidi2pdf_rails/railtie"
|
6
|
+
require "bidi2pdf_rails/chromedriver_manager_singleton"
|
7
|
+
require "bidi2pdf_rails/log_subscriber"
|
11
8
|
|
12
9
|
module Bidi2pdfRails
|
13
10
|
class << self
|
14
|
-
attr_accessor :logger, :notification_service, :verbosity, :default_timeout, :remote_browser_url, :cookies,
|
11
|
+
attr_accessor :logger, :notification_service, :verbosity, :default_timeout, :log_network_events, :log_browser_console, :remote_browser_url, :cookies,
|
15
12
|
:headers, :auth, :headless, :chromedriver_port, :chrome_session_args,
|
16
13
|
:proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :install_dir,
|
17
|
-
:
|
14
|
+
:viewport_width, :viewport_height,
|
18
15
|
:pdf_margin_top, :pdf_margin_bottom, :pdf_margin_left, :pdf_margin_right,
|
19
|
-
:pdf_scale, :
|
20
|
-
:wait_for_network_idle, :wait_for_page_loaded, :wait_for_page_check_script
|
16
|
+
:pdf_scale, :pdf_print_background, :pdf_format, :pdf_orientation, :verbosity
|
21
17
|
|
22
18
|
# Allow configuration through a block
|
23
19
|
def configure
|
24
20
|
yield self if block_given?
|
25
21
|
|
26
|
-
validate_print_options! print_options
|
27
22
|
apply_bidi2pdf_config
|
28
23
|
end
|
29
24
|
|
30
|
-
def validate_print_options!(opts)
|
31
|
-
validator = Bidi2pdf::Bidi::Commands::PrintParametersValidator.new(opts)
|
32
|
-
|
33
|
-
validator.validate!
|
34
|
-
end
|
35
|
-
|
36
|
-
def print_options(overrides = {})
|
37
|
-
overrides ||= {}
|
38
|
-
opts = {}
|
39
|
-
|
40
|
-
opts[:background] = pdf_print_background unless pdf_print_background.nil?
|
41
|
-
opts[:orientation] = pdf_orientation unless pdf_orientation.nil?
|
42
|
-
opts[:scale] = pdf_scale unless pdf_scale.nil?
|
43
|
-
opts[:shrinkToFit] = pdf_shrink_to_fit unless pdf_shrink_to_fit.nil?
|
44
|
-
|
45
|
-
# Margins
|
46
|
-
margins = {
|
47
|
-
top: @pdf_margin_top,
|
48
|
-
bottom: @pdf_margin_bottom,
|
49
|
-
left: @pdf_margin_left,
|
50
|
-
right: @pdf_margin_right
|
51
|
-
}.compact
|
52
|
-
|
53
|
-
opts[:margin] = margins unless margins.empty?
|
54
|
-
|
55
|
-
# Page size
|
56
|
-
page = {
|
57
|
-
width: @pdf_page_width,
|
58
|
-
height: @pdf_page_height,
|
59
|
-
format: @pdf_page_format
|
60
|
-
}.compact
|
61
|
-
|
62
|
-
page = overrides[:page].compact if overrides[:page]&.compact.present?
|
63
|
-
|
64
|
-
opts[:page] = page unless page.empty?
|
65
|
-
|
66
|
-
opts.deep_merge(overrides)
|
67
|
-
end
|
68
|
-
|
69
25
|
def apply_bidi2pdf_config
|
70
26
|
# Allow configuration through a block
|
71
27
|
Bidi2pdf.configure do |config|
|
@@ -74,8 +30,17 @@ module Bidi2pdfRails
|
|
74
30
|
config.logger = logger.tagged("bidi2pdf")
|
75
31
|
config.default_timeout = default_timeout
|
76
32
|
|
77
|
-
|
78
|
-
|
33
|
+
if log_network_events
|
34
|
+
config.network_events_logger = logger.tagged("bidi2pdf", "network")
|
35
|
+
else
|
36
|
+
config.network_events_logger = Logger.new(nil) # Disable network events logging
|
37
|
+
end
|
38
|
+
|
39
|
+
if log_browser_console
|
40
|
+
config.browser_console_logger = logger.tagged("bidi2pdf", "browser_console")
|
41
|
+
else
|
42
|
+
config.browser_console_logger = Logger.new(nil) # Disable browser console logging
|
43
|
+
end
|
79
44
|
|
80
45
|
config.enable_default_logging_subscriber = false
|
81
46
|
end
|
@@ -92,17 +57,11 @@ module Bidi2pdfRails
|
|
92
57
|
end
|
93
58
|
end
|
94
59
|
|
95
|
-
def use_local_chromedriver?
|
96
|
-
!use_remote_browser?
|
97
|
-
end
|
98
|
-
|
99
|
-
def use_remote_browser?
|
100
|
-
remote_browser_url.present?
|
101
|
-
end
|
102
|
-
|
103
60
|
def reset_to_defaults!
|
104
61
|
@logger = nil
|
105
62
|
@default_timeout = 10
|
63
|
+
@log_network_events = false
|
64
|
+
@log_browser_console = true
|
106
65
|
@verbosity = 0
|
107
66
|
@remote_browser_url = nil
|
108
67
|
@cookies = {}
|
@@ -117,19 +76,6 @@ module Bidi2pdfRails
|
|
117
76
|
@proxy_user = nil
|
118
77
|
@proxy_pass = nil
|
119
78
|
@install_dir = nil
|
120
|
-
|
121
|
-
@wait_for_network_idle = true
|
122
|
-
@wait_for_page_loaded = false
|
123
|
-
@wait_for_page_check_script = nil
|
124
|
-
|
125
|
-
@pdf_print_background = true
|
126
|
-
@pdf_orientation = "portrait"
|
127
|
-
@pdf_page_width = Bidi2pdf::PAPER_FORMATS_CM[:a4][:width]
|
128
|
-
@pdf_page_height = Bidi2pdf::PAPER_FORMATS_CM[:a4][:height]
|
129
|
-
@pdf_page_format = nil
|
130
|
-
|
131
|
-
@pdf_shrink_to_fit = nil
|
132
|
-
@pdf_scale = 1.0
|
133
79
|
end
|
134
80
|
|
135
81
|
def logger
|
@@ -19,6 +19,12 @@ module Bidi2pdfRails
|
|
19
19
|
@proxy_port = ask("Proxy port (e.g., 8080):", :yellow)
|
20
20
|
end
|
21
21
|
|
22
|
+
@configure_viewport = yes?("Configure custom viewport? (y/n)", :green)
|
23
|
+
if @configure_viewport
|
24
|
+
@viewport_width = ask("Viewport width (e.g., 1920):", :yellow)
|
25
|
+
@viewport_height = ask("Viewport height (e.g., 1080):", :yellow)
|
26
|
+
end
|
27
|
+
|
22
28
|
@configure_pdf = yes?("Configure custom PDF settings? (y/n)", :green)
|
23
29
|
if @configure_pdf
|
24
30
|
@pdf_orientation = ask("PDF orientation (portrait/landscape):", :yellow)
|
@@ -29,15 +35,8 @@ module Bidi2pdfRails
|
|
29
35
|
@pdf_margin_left = ask("PDF margin left (mm):", :yellow)
|
30
36
|
@pdf_margin_right = ask("PDF margin right (mm):", :yellow)
|
31
37
|
end
|
32
|
-
@pdf_page = yes?("Configure PDF page size? (y/n)", :green)
|
33
|
-
if @pdf_page
|
34
|
-
@pdf_page_width = ask("PDF page width (mm):", :yellow)
|
35
|
-
@pdf_page_height = ask("PDF page height (mm):", :yellow)
|
36
|
-
end
|
37
|
-
|
38
38
|
@pdf_print_background = yes?("Print background graphics? (y/n)", :green)
|
39
39
|
@pdf_scale = ask("PDF scale (e.g., 1.0):", :yellow)
|
40
|
-
@shrink_to_fit = ask("Shrink to fit? (y/n)", :green)
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
@@ -9,12 +9,13 @@ Bidi2pdfRails.configure do |config|
|
|
9
9
|
config.verbosity = overrides.verbosity.nil? ? :none : overrides.verbosity
|
10
10
|
config.default_timeout = 10
|
11
11
|
|
12
|
+
# Logging options
|
13
|
+
config.log_network_events = <%= @log_network_events ? "true" : "false" %>
|
14
|
+
config.log_browser_console = <%= @log_browser_console ? "true" : "false" %>
|
15
|
+
|
12
16
|
# Chrome & BiDi
|
13
17
|
# config.remote_browser_url = nil
|
14
18
|
config.headless = overrides.headless.nil? ? <%= @headless ? "true" : "false" %> : overrides.headless
|
15
|
-
#
|
16
|
-
# alternative to remote_browser_url
|
17
|
-
#
|
18
19
|
# config.chromedriver_port = 0
|
19
20
|
# config.chrome_session_args = [
|
20
21
|
# "--disable-gpu",
|
@@ -33,56 +34,41 @@ Bidi2pdfRails.configure do |config|
|
|
33
34
|
# config.proxy_pass = nil
|
34
35
|
<% end %>
|
35
36
|
|
36
|
-
|
37
|
-
|
37
|
+
<% if @configure_viewport %>
|
38
|
+
# Viewport settings
|
39
|
+
config.viewport_width = <%= @viewport_width || 1920 %>
|
40
|
+
config.viewport_height = <%= @viewport_height || 1080 %>
|
41
|
+
<% else %>
|
42
|
+
# Viewport settings
|
43
|
+
# config.viewport_width = 1920
|
44
|
+
# config.viewport_height = 1080
|
45
|
+
<% end %>
|
38
46
|
|
47
|
+
<% if @configure_pdf %>
|
48
|
+
# PDF settings
|
39
49
|
config.pdf_orientation = "<%= @pdf_orientation || "portrait" %>"
|
40
50
|
<% if @pdf_margins %>
|
41
|
-
config.pdf_margin_top = <%= @pdf_margin_top ||
|
42
|
-
config.pdf_margin_bottom = <%= @pdf_margin_bottom ||
|
43
|
-
config.pdf_margin_left = <%= @pdf_margin_left ||
|
44
|
-
config.pdf_margin_right = <%= @pdf_margin_right ||
|
45
|
-
<% else %>
|
46
|
-
# config.pdf_margin_top = 2.5
|
47
|
-
# config.pdf_margin_bottom = 2
|
48
|
-
# config.pdf_margin_left = 2
|
49
|
-
# config.pdf_margin_right = 2
|
50
|
-
<% end %>
|
51
|
-
|
52
|
-
<% if @pdf_page %>
|
53
|
-
# Page settings
|
54
|
-
config.pdf_page_width = <%= @pdf_page_width || Bidi2pdf::PAPER_FORMATS_CM[:a4][:width] %>
|
55
|
-
config.pdf_page_height = <%= @pdf_page_height || Bidi2pdf::PAPER_FORMATS_CM[:a4][:height] %>
|
51
|
+
config.pdf_margin_top = <%= @pdf_margin_top || 10 %>
|
52
|
+
config.pdf_margin_bottom = <%= @pdf_margin_bottom || 10 %>
|
53
|
+
config.pdf_margin_left = <%= @pdf_margin_left || 10 %>
|
54
|
+
config.pdf_margin_right = <%= @pdf_margin_right || 10 %>
|
56
55
|
<% else %>
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
#
|
62
|
-
# config.pdf_page_width = <%= Bidi2pdf::PAPER_FORMATS_CM[:a4][:width] %>
|
63
|
-
# config.pdf_page_height = <%= Bidi2pdf::PAPER_FORMATS_CM[:a4][:height] %>
|
56
|
+
# config.pdf_margin_top = 10
|
57
|
+
# config.pdf_margin_bottom = 10
|
58
|
+
# config.pdf_margin_left = 10
|
59
|
+
# config.pdf_margin_right = 10
|
64
60
|
<% end %>
|
65
|
-
|
66
61
|
config.pdf_print_background = <%= @pdf_print_background ? "true" : "false" %>
|
67
62
|
config.pdf_scale = <%= @pdf_scale || 1.0 %>
|
68
|
-
config.shrink_to_fit = <%= @shrink_to_fit ? "true" : "false" %>
|
69
63
|
<% else %>
|
64
|
+
# PDF settings
|
70
65
|
# config.pdf_orientation = "portrait"
|
71
|
-
# config.pdf_margin_top =
|
72
|
-
# config.pdf_margin_bottom =
|
73
|
-
# config.pdf_margin_left =
|
74
|
-
# config.pdf_margin_right =
|
66
|
+
# config.pdf_margin_top = 10
|
67
|
+
# config.pdf_margin_bottom = 10
|
68
|
+
# config.pdf_margin_left = 10
|
69
|
+
# config.pdf_margin_right = 10
|
75
70
|
# config.pdf_print_background = true
|
76
71
|
# config.pdf_scale = 1.0
|
77
|
-
# config.shrink_to_fit = true
|
78
|
-
|
79
|
-
# Page settings
|
80
|
-
# config.pdf_page_format = "A4"
|
81
|
-
#
|
82
|
-
# or custom page size
|
83
|
-
#
|
84
|
-
# config.pdf_page_width = <%= Bidi2pdf::PAPER_FORMATS_CM[:a4][:width] %>
|
85
|
-
# config.pdf_page_height = <%= Bidi2pdf::PAPER_FORMATS_CM[:a4][:height] %>
|
86
72
|
<% end %>
|
87
73
|
|
88
74
|
# config.cookies = [
|
@@ -100,22 +86,4 @@ Bidi2pdfRails.configure do |config|
|
|
100
86
|
|
101
87
|
# chromedriver install dir
|
102
88
|
# config.install_dir = Rails.root.join("tmp", "bidi2pdf").to_s
|
103
|
-
|
104
|
-
# wait for the page to load settings
|
105
|
-
# config.wait_for_network_idle = true
|
106
|
-
# config.wait_for_page_loaded = false
|
107
|
-
# this script can be any valid JS script that returns a Promise
|
108
|
-
# it will wait for the Promise to resolve
|
109
|
-
# config.wait_for_page_check_script = nil
|
110
|
-
end
|
111
|
-
|
112
|
-
Rails.application.config.after_initialize do
|
113
|
-
Bidi2pdfRails::MainLogSubscriber.attach_to "bidi2pdf", inherit_all: true # needed for imported methods
|
114
|
-
Bidi2pdfRails::MainLogSubscriber.attach_to "bidi2pdf_rails", inherit_all: true # needed for imported methods
|
115
|
-
|
116
|
-
Bidi2pdfRails::BrowserConsoleLogSubscriber.attach_to "bidi2pdf"
|
117
|
-
|
118
|
-
Bidi2pdfRails::MainLogSubscriber.silence /network_event_.*\.bidi2pdf/
|
119
|
-
|
120
|
-
Bidi2pdfRails::NetworkLogSubscriber.attach_to "bidi2pdf"
|
121
89
|
end
|
@@ -5,8 +5,4 @@ class ReportsController < ApplicationController
|
|
5
5
|
format.pdf { render pdf: 'my-report', layout: 'pdf' }
|
6
6
|
end
|
7
7
|
end
|
8
|
-
|
9
|
-
def print_remote
|
10
|
-
render pdf: 'remote-report', url: "http://example.com", wait_for_page_loaded: false, print_options: { page: { format: :A4 } }
|
11
|
-
end
|
12
8
|
end
|
@@ -46,7 +46,7 @@ Rails.application.configure do
|
|
46
46
|
.then { |logger| ActiveSupport::TaggedLogging.new(logger) }
|
47
47
|
|
48
48
|
# Prepend all log lines with the following tags.
|
49
|
-
config.log_tags = [:request_id]
|
49
|
+
config.log_tags = [ :request_id ]
|
50
50
|
|
51
51
|
# "info" includes generic and useful information about system operation, but avoids logging too much
|
52
52
|
# information to avoid inadvertent exposure of personally identifiable information (PII). If you
|
@@ -9,6 +9,10 @@ Bidi2pdfRails.configure do |config|
|
|
9
9
|
config.verbosity = overrides.verbosity.nil? ? :none : overrides.verbosity
|
10
10
|
config.default_timeout = 10
|
11
11
|
|
12
|
+
# Logging options
|
13
|
+
config.log_network_events = false
|
14
|
+
config.log_browser_console = false
|
15
|
+
|
12
16
|
# Chrome & BiDi
|
13
17
|
# config.remote_browser_url = nil
|
14
18
|
config.headless = overrides.headless.nil? ? false : overrides.headless
|
@@ -18,24 +22,30 @@ Bidi2pdfRails.configure do |config|
|
|
18
22
|
# "--no-sandbox"
|
19
23
|
# ]
|
20
24
|
|
25
|
+
|
21
26
|
# config.proxy_addr = nil
|
22
27
|
# config.proxy_port = nil
|
23
28
|
# config.proxy_user = nil
|
24
29
|
# config.proxy_pass = nil
|
25
30
|
|
31
|
+
|
32
|
+
|
26
33
|
# Viewport settings
|
27
34
|
# config.viewport_width = 1920
|
28
35
|
# config.viewport_height = 1080
|
29
36
|
|
37
|
+
|
38
|
+
|
30
39
|
# PDF settings
|
31
|
-
config.pdf_orientation = "portrait"
|
32
|
-
config.pdf_margin_top =
|
33
|
-
config.pdf_margin_bottom =
|
34
|
-
config.pdf_margin_left =
|
35
|
-
config.pdf_margin_right =
|
36
|
-
config.pdf_print_background = true
|
40
|
+
# config.pdf_orientation = "portrait"
|
41
|
+
# config.pdf_margin_top = 10
|
42
|
+
# config.pdf_margin_bottom = 10
|
43
|
+
# config.pdf_margin_left = 10
|
44
|
+
# config.pdf_margin_right = 10
|
45
|
+
# config.pdf_print_background = true
|
37
46
|
# config.pdf_scale = 1.0
|
38
47
|
|
48
|
+
|
39
49
|
# config.cookies = [
|
40
50
|
# { name: "session", value: "abc123", domain: "example.com" }
|
41
51
|
# ]
|
@@ -51,18 +61,4 @@ Bidi2pdfRails.configure do |config|
|
|
51
61
|
|
52
62
|
# chromedriver install dir
|
53
63
|
# config.install_dir = Rails.root.join("tmp", "bidi2pdf").to_s
|
54
|
-
|
55
|
-
# wait for the page to load settings
|
56
|
-
config.wait_for_network_idle = true
|
57
|
-
config.wait_for_page_loaded = true
|
58
|
-
# config.wait_for_page_check_script = nil
|
59
|
-
end
|
60
|
-
|
61
|
-
Rails.application.config.after_initialize do
|
62
|
-
Bidi2pdfRails::MainLogSubscriber.attach_to "bidi2pdf", inherit_all: true # needed for imported methods
|
63
|
-
Bidi2pdfRails::MainLogSubscriber.attach_to "bidi2pdf_rails", inherit_all: true # needed for imported methods
|
64
|
-
Bidi2pdfRails::BrowserConsoleLogSubscriber.attach_to "bidi2pdf"
|
65
|
-
Bidi2pdfRails::NetworkLogSubscriber.attach_to "bidi2pdf"
|
66
|
-
|
67
|
-
Bidi2pdfRails::MainLogSubscriber.silence /network_event_.*\.bidi2pdf/
|
68
64
|
end
|
data/spec/dummy/config/routes.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
2
|
get "reports/:id" => "reports#show", as: :report
|
3
3
|
|
4
|
-
get "print-remote" => "reports#print_remote", as: :print_remote
|
5
|
-
|
6
4
|
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
|
7
5
|
|
8
6
|
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
|