Class: Bidi2pdfRails::Services::PdfRenderer
- Inherits:
-
Object
- Object
- Bidi2pdfRails::Services::PdfRenderer
- Defined in:
- lib/bidi2pdf_rails/services/pdf_renderer.rb
Overview
PdfRenderer is responsible for rendering a Rails view into a PDF using headless Chrome.
It delegates option parsing and controller-aware defaults to an options handler object, which splits responsibilities across HTML rendering, PDF configuration, and optional URL rendering.
Constant Summary collapse
- PDF_OPTIONS =
%i[ print_options asset_host wait_for_network_idle wait_for_page_loaded wait_for_page_check_script html callbacks ].freeze
- PRINT_URL_OPTIONS =
%i[ url auth headers cookies ].freeze
Instance Attribute Summary collapse
-
#options_handler ⇒ Object
readonly
Returns the value of attribute options_handler.
Instance Method Summary collapse
-
#initialize(options_handler) ⇒ PdfRenderer
constructor
A new instance of PdfRenderer.
- #render_pdf ⇒ Object
Constructor Details
#initialize(options_handler) ⇒ PdfRenderer
Returns a new instance of PdfRenderer.
42 43 44 |
# File 'lib/bidi2pdf_rails/services/pdf_renderer.rb', line 42 def initialize() @options_handler = end |
Instance Attribute Details
#options_handler ⇒ Object (readonly)
Returns the value of attribute options_handler.
40 41 42 |
# File 'lib/bidi2pdf_rails/services/pdf_renderer.rb', line 40 def @options_handler end |
Instance Method Details
#render_pdf ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/bidi2pdf_rails/services/pdf_renderer.rb', line 46 def render_pdf ActiveSupport::Notifications.instrument("handle_printing.bidi2pdf_rails") do if .url.url? headers = .url.headers = .url. auth = .url.auth UrlToPdfConverter.new(.url.url, headers: headers, cookies: , auth: auth, print_options: .pdf., wait_for_network_idle: .pdf.wait_for_network_idle, wait_for_page_loaded: .pdf.wait_for_page_loaded, wait_for_page_check_script: .pdf.wait_for_page_check_script, custom_css: .pdf.custom_css, custom_css_url: .pdf.custom_css_url, custom_js: .pdf.custom_js, custom_js_url: .pdf.custom_js_url, callbacks: .pdf.callbacks ).generate else HtmlToPdfConverter.new(.html.html, print_options: .pdf., wait_for_network_idle: .pdf.wait_for_network_idle, wait_for_page_loaded: .pdf.wait_for_page_loaded, wait_for_page_check_script: .pdf.wait_for_page_check_script, custom_css: .pdf.custom_css, custom_css_url: .pdf.custom_css_url, custom_js: .pdf.custom_js, custom_js_url: .pdf.custom_js_url, callbacks: .pdf.callbacks ).generate end end end |