bidi2pdf-rails 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.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/.idea/.gitignore +8 -0
  3. data/.idea/bidi2pdf-rails.iml +411 -0
  4. data/.idea/inspectionProfiles/profiles_settings.xml +5 -0
  5. data/.idea/misc.xml +4 -0
  6. data/.idea/modules.xml +8 -0
  7. data/.idea/vcs.xml +6 -0
  8. data/.rspec +3 -0
  9. data/.rubocop.yml +90 -0
  10. data/.ruby-gemset +1 -0
  11. data/.ruby-version +1 -0
  12. data/MIT-LICENSE +20 -0
  13. data/README.md +75 -0
  14. data/Rakefile +11 -0
  15. data/lib/bidi2pdf-rails.rb +4 -0
  16. data/lib/bidi2pdf_rails/chromedriver_manager_singleton.rb +69 -0
  17. data/lib/bidi2pdf_rails/log_subscriber.rb +13 -0
  18. data/lib/bidi2pdf_rails/railtie.rb +79 -0
  19. data/lib/bidi2pdf_rails/version.rb +3 -0
  20. data/lib/bidi2pdf_rails.rb +87 -0
  21. data/lib/generators/bidi2pdf_rails/USAGE +8 -0
  22. data/lib/generators/bidi2pdf_rails/initializer_generator.rb +73 -0
  23. data/lib/generators/bidi2pdf_rails/templates/bidi2pdf_rails.rb.tt +89 -0
  24. data/spec/bidi2pdf_rails/bidi2pdf_rails_spec.rb +9 -0
  25. data/spec/dummy/Rakefile +6 -0
  26. data/spec/dummy/app/assets/images/img.jpg +0 -0
  27. data/spec/dummy/app/assets/javascripts/paged.polyfill-4.3.js +33251 -0
  28. data/spec/dummy/app/assets/stylesheets/application.css +1 -0
  29. data/spec/dummy/app/assets/stylesheets/pdf.css +121 -0
  30. data/spec/dummy/app/assets/stylesheets/reset.css +449 -0
  31. data/spec/dummy/app/assets/stylesheets/screen.css +281 -0
  32. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  33. data/spec/dummy/app/controllers/reports_controller.rb +8 -0
  34. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  35. data/spec/dummy/app/helpers/reports_helper.rb +2 -0
  36. data/spec/dummy/app/views/layouts/application.html.erb +67 -0
  37. data/spec/dummy/app/views/layouts/pdf.html.erb +67 -0
  38. data/spec/dummy/app/views/pwa/manifest.json.erb +22 -0
  39. data/spec/dummy/app/views/pwa/service-worker.js +26 -0
  40. data/spec/dummy/app/views/reports/show.html.erb +153 -0
  41. data/spec/dummy/bin/rails +4 -0
  42. data/spec/dummy/bin/rake +4 -0
  43. data/spec/dummy/bin/setup +29 -0
  44. data/spec/dummy/config/application.rb +40 -0
  45. data/spec/dummy/config/boot.rb +5 -0
  46. data/spec/dummy/config/environment.rb +5 -0
  47. data/spec/dummy/config/environments/development.rb +57 -0
  48. data/spec/dummy/config/environments/production.rb +73 -0
  49. data/spec/dummy/config/environments/test.rb +51 -0
  50. data/spec/dummy/config/initializers/bidi2pdf_rails.rb +64 -0
  51. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  52. data/spec/dummy/config/initializers/cors.rb +9 -0
  53. data/spec/dummy/config/initializers/filter_parameter_logging.rb +8 -0
  54. data/spec/dummy/config/initializers/inflections.rb +16 -0
  55. data/spec/dummy/config/initializers/permissions_policy.rb +13 -0
  56. data/spec/dummy/config/locales/en.yml +31 -0
  57. data/spec/dummy/config/puma.rb +34 -0
  58. data/spec/dummy/config/routes.rb +16 -0
  59. data/spec/dummy/config.ru +6 -0
  60. data/spec/dummy/log/development.log +220 -0
  61. data/spec/dummy/public/404.html +67 -0
  62. data/spec/dummy/public/406-unsupported-browser.html +66 -0
  63. data/spec/dummy/public/422.html +67 -0
  64. data/spec/dummy/public/500.html +66 -0
  65. data/spec/dummy/public/icon.png +0 -0
  66. data/spec/dummy/public/icon.svg +3 -0
  67. data/spec/dummy/spec/helpers/reports_helper_spec.rb +15 -0
  68. data/spec/dummy/spec/requests/reports_spec.rb +10 -0
  69. data/spec/dummy/spec/views/reports/show.html.erb_spec.rb +5 -0
  70. data/spec/dummy/storage/test.sqlite3 +0 -0
  71. data/spec/dummy/tmp/README.md +69 -0
  72. data/spec/dummy/tmp/local_secret.txt +1 -0
  73. data/spec/dummy/tmp/pids/server.pid +1 -0
  74. data/spec/dummy/tmp/restart.txt +0 -0
  75. data/spec/generator/bidie2pdf_rails_initializer_generator_spec.rb +5 -0
  76. data/spec/generator/initializer_generator_spec.rb +5 -0
  77. data/spec/rails_helper.rb +60 -0
  78. data/spec/requests/reports_spec.rb +17 -0
  79. data/spec/spec_helper.rb +94 -0
  80. data/tasks/bidi2pdf_rails_tasks.rake +4 -0
  81. metadata +289 -0
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ [![Build Status](https://github.com/dieter-medium/bidi2pdf-rails/actions/workflows/ruby.yml/badge.svg)](https://github.com/dieter-medium/bidi2pdf-rails/blob/main/.github/workflows/ruby.yml)
2
+ [![Maintainability](https://api.codeclimate.com/v1/badges/6425d9893aa3a9ca243e/maintainability)](https://codeclimate.com/github/dieter-medium/bidi2pdf-rails/maintainability)
3
+ [![Gem Version](https://badge.fury.io/rb/bidi2pdf-rails.svg)](https://badge.fury.io/rb/bidi2pdf-rails)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/6425d9893aa3a9ca243e/test_coverage)](https://codeclimate.com/github/dieter-medium/bidi2pdf-rails/test_coverage)
5
+ [![Open Source Helpers](https://www.codetriage.com/dieter-medium/bidi2pdf-rails/badges/users.svg)](https://www.codetriage.com/dieter-medium/bidi2pdf-rails)
6
+
7
+
8
+ # 📄 Bidi2pdfRails
9
+
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.
12
+
13
+ > **⚠️ Note:** This project is currently **under development** and **not yet recommended for production use**.
14
+
15
+ ---
16
+
17
+ ## 🚀 Why Bidi2pdfRails?
18
+
19
+ - Utilizes modern browser technologies for accurate rendering (similar to `grover` or `wicked_pdf`)
20
+ - Easy to integrate into existing Rails projects
21
+ - Configurable options: URL, output path, rendering settings
22
+
23
+ ---
24
+
25
+ ## 🔧 Installation
26
+
27
+ Add the following lines to your `Gemfile`:
28
+
29
+ ```ruby
30
+ gem "bidi2pdf-rails"
31
+ # As long as the gem is not published, use:
32
+ gem "bidi2pdf-rails", github: "dieter-medium/bidi2pdf", branch: "main"
33
+ gem "bidi2pdf", github: "dieter-medium/bidi2pdf", branch: "main"
34
+ ```
35
+
36
+ Then install the dependencies:
37
+
38
+ ```bash
39
+ bundle
40
+ ```
41
+
42
+ Generate the initializer:
43
+
44
+ ```bash
45
+ bin/rails generate bidi2pdf_rails:initializer
46
+ ```
47
+
48
+ Alternatively, install it manually:
49
+
50
+ ```bash
51
+ gem install bidi2pdf-rails
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 🧪 Example & Getting Started
57
+
58
+ You can find a full example inside the [`spec/dummy`](spec/dummy) directory of this repository.
59
+ This demonstrates how to use `Bidi2pdfRails` in a realistic mini Rails application setup.
60
+
61
+ ---
62
+
63
+ ## 🙌 Contributing
64
+
65
+ Want to contribute?
66
+ Pull requests, bug reports, and ideas are warmly welcome!
67
+
68
+ *Contribution guidelines will be added soon.*
69
+
70
+ ---
71
+
72
+ ## 📄 License
73
+
74
+ This gem is open-source and available under the terms of the [MIT License](https://opensource.org/licenses/MIT).
75
+ Free to use – with responsibility.
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/setup"
2
+
3
+ require "bundler/gem_tasks"
4
+
5
+ require 'rspec/core/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ require "rubocop/rake_task"
10
+
11
+ RuboCop::RakeTask.new
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ # just to get the nicer gem name
4
+ require_relative "bidi2pdf_rails"
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bidi2pdfRails
4
+ module ChromedriverManagerSingleton
5
+ class << self
6
+ attr_reader :manager, :session
7
+
8
+ def initialize_manager
9
+ return unless running_as_server?
10
+
11
+ @mutex ||= Mutex.new
12
+ @mutex.synchronize do
13
+ return if @manager && @session
14
+
15
+ msg = Bidi2pdfRails.remote_browser_url ? "Remote session" : "ChromeDriver manager"
16
+
17
+ Bidi2pdfRails.logger.info "Initializing Bidi2pdf #{msg}"
18
+
19
+ if Bidi2pdfRails.remote_browser_url
20
+ @session = Bidi::Session.new(
21
+ session_url: Bidi2pdfRails.remote_browser_url,
22
+ headless: Bidi2pdfRails.headless,
23
+ chrome_args: Bidi2pdfRails.chrome_session_args
24
+ )
25
+ else
26
+ @manager = Bidi2pdf::ChromedriverManager.new(
27
+ port: Bidi2pdfRails.chromedriver_port,
28
+ headless: Bidi2pdfRails.headless,
29
+ chrome_args: Bidi2pdfRails.chrome_session_args
30
+ )
31
+ @manager.start
32
+ @session = @manager.session
33
+ end
34
+
35
+ @session.start
36
+ @session.client.on_close { Bidi2pdfRails.logger.info "WebSocket session closed" }
37
+ end
38
+ end
39
+
40
+ def shutdown
41
+ return unless running_as_server?
42
+
43
+ @mutex ||= Mutex.new
44
+ @mutex.synchronize do
45
+ msg = Bidi2pdfRails.remote_browser_url ? "Remote session" : "ChromeDriver manager"
46
+ Bidi2pdfRails.logger.info "Shutting down Bidi2pdf #{msg}"
47
+ @session&.close
48
+ @manager&.stop
49
+ @session = nil
50
+ @manager = nil
51
+ end
52
+ end
53
+
54
+ def running_as_server?
55
+ return false if Rails.const_defined?(:Console)
56
+ return false if defined?(Rails::Generators)
57
+
58
+ return false if File.basename($0) == "rake"
59
+
60
+ # Covers common Rails server entrypoints
61
+ server_commands = %w[server puma unicorn passenger thin webrick rackup]
62
+ cmdline = File.basename($0)
63
+
64
+ server_commands.any? { |s| cmdline.include?(s) } ||
65
+ Rails.const_defined?("Server")
66
+ end
67
+ end
68
+ end
69
+ end
@@ -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
@@ -0,0 +1,79 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Bidi2pdfRails
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "bidi2pdf_rails.add_mime_type" do
6
+ Mime::Type.register "application/pdf", :pdf unless Mime::Type.lookup_by_extension(:pdf)
7
+ end
8
+
9
+ initializer "bidi2pdf_rails.initialize_chromedriver_manager", after: :load_config_initializers do
10
+ Bidi2pdfRails.apply_bidi2pdf_config
11
+
12
+ Rails.application.config.after_initialize do
13
+ ChromedriverManagerSingleton.initialize_manager
14
+ end
15
+ end
16
+
17
+ config.after_initialize do
18
+ # Set up shutdown hook for when the application stops
19
+ at_exit do
20
+ ChromedriverManagerSingleton.shutdown
21
+ end
22
+ end
23
+
24
+ initializer "bidi2pdf_rails.add_pdf_renderer" do
25
+ ActionController::Renderers.add :pdf do |filename, options|
26
+ pdf_data = ""
27
+ options = options.dup
28
+
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
52
+
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),
70
+ type: Mime[:pdf],
71
+ filename: "#{filename}.pdf",
72
+ disposition: options.fetch(:disposition, "inline")
73
+ ensure
74
+
75
+ ActionController::Base.asset_host = original_asset_host
76
+ end
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,3 @@
1
+ module Bidi2pdfRails
2
+ VERSION = "0.0.1.pre.alpha"
3
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bidi2pdf"
4
+ require "bidi2pdf_rails/version"
5
+ require "bidi2pdf_rails/railtie"
6
+ require "bidi2pdf_rails/chromedriver_manager_singleton"
7
+ require "bidi2pdf_rails/log_subscriber"
8
+
9
+ module Bidi2pdfRails
10
+ class << self
11
+ attr_accessor :logger, :notification_service, :verbosity, :default_timeout, :log_network_events, :log_browser_console, :remote_browser_url, :cookies,
12
+ :headers, :auth, :headless, :chromedriver_port, :chrome_session_args,
13
+ :proxy_addr, :proxy_port, :proxy_user, :proxy_pass, :install_dir,
14
+ :viewport_width, :viewport_height,
15
+ :pdf_margin_top, :pdf_margin_bottom, :pdf_margin_left, :pdf_margin_right,
16
+ :pdf_scale, :pdf_print_background, :pdf_format, :pdf_orientation, :verbosity
17
+
18
+ # Allow configuration through a block
19
+ def configure
20
+ yield self if block_given?
21
+
22
+ apply_bidi2pdf_config
23
+ end
24
+
25
+ def apply_bidi2pdf_config
26
+ # Allow configuration through a block
27
+ Bidi2pdf.configure do |config|
28
+ config.notification_service = notification_service
29
+
30
+ config.logger = logger.tagged("bidi2pdf")
31
+ config.default_timeout = default_timeout
32
+
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
44
+
45
+ config.enable_default_logging_subscriber = false
46
+ end
47
+
48
+ Chromedriver::Binary.configure do |config|
49
+ config.logger = logger
50
+
51
+ config.proxy_addr = proxy_addr
52
+ config.proxy_port = proxy_port
53
+ config.proxy_user = proxy_user
54
+ config.proxy_pass = proxy_pass
55
+
56
+ config.install_dir = install_dir
57
+ end
58
+ end
59
+
60
+ def reset_to_defaults!
61
+ @logger = nil
62
+ @default_timeout = 10
63
+ @log_network_events = false
64
+ @log_browser_console = true
65
+ @verbosity = 0
66
+ @remote_browser_url = nil
67
+ @cookies = {}
68
+ @headers = {}
69
+ @auth = nil
70
+ @headless = !Rails.env.development?
71
+ @chromedriver_port = 0
72
+ @chrome_session_args = Bidi2pdf::Bidi::Session::DEFAULT_CHROME_ARGS
73
+
74
+ @proxy_addr = nil
75
+ @proxy_port = nil
76
+ @proxy_user = nil
77
+ @proxy_pass = nil
78
+ @install_dir = nil
79
+ end
80
+
81
+ def logger
82
+ @logger ||= Rails.logger # lazy load the logger, after it exists
83
+ end
84
+ end
85
+
86
+ self.reset_to_defaults!
87
+ end
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ bin/rails generate initializer Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,73 @@
1
+ module Bidi2pdfRails
2
+ class InitializerGenerator < Rails::Generators::Base
3
+ source_root File.expand_path("templates", __dir__)
4
+ desc "Generates a config/initializers/bidi2pdf.rb config file"
5
+
6
+ class_option :force, type: :boolean, default: false, desc: "Overwrite existing file"
7
+ class_option :quiet, type: :boolean, default: false, desc: "Skip prompts"
8
+
9
+ def ask_questions
10
+ return if options[:quiet]
11
+
12
+ @log_network_events = yes?("Log network traffic? (y/n)", :green)
13
+ @log_browser_console = yes?("Log browser console output? (y/n)", :green)
14
+ @headless = yes?("Run Chrome in headless mode? (y/n)", :green)
15
+ @proxy = yes?("Use a proxy server? (y/n)", :green)
16
+
17
+ if @proxy
18
+ @proxy_addr = ask("Proxy address (e.g., 127.0.0.1):", :yellow)
19
+ @proxy_port = ask("Proxy port (e.g., 8080):", :yellow)
20
+ end
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
+
28
+ @configure_pdf = yes?("Configure custom PDF settings? (y/n)", :green)
29
+ if @configure_pdf
30
+ @pdf_orientation = ask("PDF orientation (portrait/landscape):", :yellow)
31
+ @pdf_margins = yes?("Configure PDF margins? (y/n)", :green)
32
+ if @pdf_margins
33
+ @pdf_margin_top = ask("PDF margin top (mm):", :yellow)
34
+ @pdf_margin_bottom = ask("PDF margin bottom (mm):", :yellow)
35
+ @pdf_margin_left = ask("PDF margin left (mm):", :yellow)
36
+ @pdf_margin_right = ask("PDF margin right (mm):", :yellow)
37
+ end
38
+ @pdf_print_background = yes?("Print background graphics? (y/n)", :green)
39
+ @pdf_scale = ask("PDF scale (e.g., 1.0):", :yellow)
40
+ end
41
+ end
42
+
43
+ def generate_config
44
+ @config_path = "config/initializers/bidi2pdf_rails.rb"
45
+
46
+ template "bidi2pdf_rails.rb.tt", @config_path
47
+ end
48
+
49
+ def inject_environment_config
50
+ env_file = "config/environments/development.rb"
51
+
52
+ if File.exist?(env_file)
53
+ if File.read(env_file).include?("config.x.bidi2pdf_rails")
54
+ say_status :skipped, "Bidi2PDF settings already present in #{env_file}", :yellow
55
+ else
56
+ content = <<~RUBY.gsub(/^(?=[\w#])/, " ")
57
+ # Custom Bidi2PDF settings, check config/initializers/bidi2pdf_rails.rb for hints
58
+ config.x.bidi2pdf_rails.headless = false
59
+ config.x.bidi2pdf_rails.verbosity = :high
60
+ # config.x.bidi2pdf_rails.log_browser_console = true
61
+ # config.x.bidi2pdf_rails.default_timeout = 60
62
+ RUBY
63
+
64
+ inject_into_file env_file, content, before: /^end\s*$/
65
+
66
+ say_status :modified, env_file, :green
67
+ end
68
+ else
69
+ say_status :error, "Could not find #{env_file}", :red
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ Bidi2pdfRails.configure do |config|
4
+ overrides = Rails.application.config.x.bidi2pdf_rails
5
+
6
+ config.notification_service = ActiveSupport::Notifications
7
+
8
+ config.logger = Rails.logger
9
+ config.verbosity = overrides.verbosity.nil? ? :none : overrides.verbosity
10
+ config.default_timeout = 10
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
+
16
+ # Chrome & BiDi
17
+ # config.remote_browser_url = nil
18
+ config.headless = overrides.headless.nil? ? <%= @headless ? "true" : "false" %> : overrides.headless
19
+ # config.chromedriver_port = 0
20
+ # config.chrome_session_args = [
21
+ # "--disable-gpu",
22
+ # "--no-sandbox"
23
+ # ]
24
+
25
+ <% if @proxy %>
26
+ config.proxy_addr = "<%= @proxy_addr %>"
27
+ config.proxy_port = <%= @proxy_port %>
28
+ config.proxy_user = nil
29
+ config.proxy_pass = nil
30
+ <% else %>
31
+ # config.proxy_addr = nil
32
+ # config.proxy_port = nil
33
+ # config.proxy_user = nil
34
+ # config.proxy_pass = nil
35
+ <% end %>
36
+
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 %>
46
+
47
+ <% if @configure_pdf %>
48
+ # PDF settings
49
+ config.pdf_orientation = "<%= @pdf_orientation || "portrait" %>"
50
+ <% if @pdf_margins %>
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 %>
55
+ <% else %>
56
+ # config.pdf_margin_top = 10
57
+ # config.pdf_margin_bottom = 10
58
+ # config.pdf_margin_left = 10
59
+ # config.pdf_margin_right = 10
60
+ <% end %>
61
+ config.pdf_print_background = <%= @pdf_print_background ? "true" : "false" %>
62
+ config.pdf_scale = <%= @pdf_scale || 1.0 %>
63
+ <% else %>
64
+ # PDF settings
65
+ # config.pdf_orientation = "portrait"
66
+ # config.pdf_margin_top = 10
67
+ # config.pdf_margin_bottom = 10
68
+ # config.pdf_margin_left = 10
69
+ # config.pdf_margin_right = 10
70
+ # config.pdf_print_background = true
71
+ # config.pdf_scale = 1.0
72
+ <% end %>
73
+
74
+ # config.cookies = [
75
+ # { name: "session", value: "abc123", domain: "example.com" }
76
+ # ]
77
+
78
+ # config.headers = {
79
+ # "X-API-KEY" => "topsecret"
80
+ # }
81
+
82
+ # config.auth = {
83
+ # username: "admin",
84
+ # password: "secret"
85
+ # }
86
+
87
+ # chromedriver install dir
88
+ # config.install_dir = Rails.root.join("tmp", "bidi2pdf").to_s
89
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../rails_helper"
4
+
5
+ RSpec.describe Bidi2pdfRails do
6
+ it "has a version number" do
7
+ expect(Bidi2pdfRails::VERSION).not_to be_nil
8
+ end
9
+ end
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require_relative "config/application"
5
+
6
+ Rails.application.load_tasks