Class: Pdf::Document::Article
- Inherits:
-
BaseService
- Object
- BaseService
- Pdf::Document::Article
- Includes:
- Base
- Defined in:
- app/services/pdf/document/article.rb
Overview
Renders article PDFs using Playwright (Chromium).
Unlike the other PDF generators that build layouts programmatically with
HexaPDF, articles are authored in a WYSIWYG editor and stored as rich HTML.
Chromium renders that HTML with perfect fidelity — links, images, inline
styles, tables — without needing a custom DOM walker.
Uses the same playwright-ruby-client already in the project for browser
automation (Menard portal uploads, etc.) — no additional Chrome binary.
Defined Under Namespace
Classes: GenerationError, Result
Constant Summary collapse
- LOGO_PATH =
Pdf::Config::LOGO_PATH
- CONTENT_TIMEOUT =
30_000- CHROMIUM_ARGS =
%w[--no-sandbox --disable-dev-shm-usage --disable-gpu].freeze
Constants included from Base
Base::FONT, Base::NIMBUS_SANS_PATH, Base::NIMBUS_SANS_PATH_BOLD, Base::WY_LOGO_PATH
Instance Method Summary collapse
Instance Method Details
#call(article) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'app/services/pdf/document/article.rb', line 25 def call(article) require 'playwright' html = build_html(article) pdf_data = generate_pdf(html) Result.new(pdf: pdf_data, file_name: article.file_name) rescue Playwright::Error, Playwright::TimeoutError => e Rails.logger.error("[Pdf::Document::Article] Playwright error for #{article.file_name}: #{e.class} — #{e.}") raise GenerationError, "Article PDF generation failed: #{e.}" rescue StandardError => e Rails.logger.error("[Pdf::Document::Article] Failed for #{article.file_name}: #{e.class} — #{e.}") raise GenerationError, "Article PDF generation failed: #{e.}" end |