Class: Vivlio::Starter::Pdf::StandardProvider
- Inherits:
-
Object
- Object
- Vivlio::Starter::Pdf::StandardProvider
- Defined in:
- lib/vivlio/starter/cli/pdf/standard_provider.rb
Overview
MITライセンス互換の標準プロバイダ
Instance Method Summary collapse
-
#add_outline!(_original_pdf_path, _items, max_level:) ⇒ Boolean
PDF アウトラインを付与する (Standard モードではスキップ).
-
#ensure_blank_page_pdf(path, width_pt, height_pt) ⇒ String
空白ページのPDFを生成する.
-
#page_count(pdf_path) ⇒ Integer?
PDF のページ数を取得する.
-
#stamp_nombre!(original_pdf_path, bleed_pt: 3.0 * (72.0 / 25.4)) ⇒ Boolean
入稿用 PDF に隠しノンブルを書き込む.
Instance Method Details
#add_outline!(_original_pdf_path, _items, max_level:) ⇒ Boolean
PDF アウトラインを付与する (Standard モードではスキップ)
73 74 75 76 77 |
# File 'lib/vivlio/starter/cli/pdf/standard_provider.rb', line 73 def add_outline!(_original_pdf_path, _items, max_level:) # rubocop:disable Lint/UnusedMethodArgument CLI::Common.log_warn('PDF しおり(アウトライン)の付与は Standard モード(MIT) ではサポートされていません。') CLI::Common.log_info(' => 拡張機能が必要な場合は `gem install vivlio-starter-pdf` を検討してください。') false end |
#ensure_blank_page_pdf(path, width_pt, height_pt) ⇒ String
空白ページのPDFを生成する
29 30 31 32 33 34 |
# File 'lib/vivlio/starter/cli/pdf/standard_provider.rb', line 29 def ensure_blank_page_pdf(path, width_pt, height_pt) return path if File.exist?(path) Prawn::Document.generate(path, page_size: [width_pt, height_pt]) {} path end |
#page_count(pdf_path) ⇒ Integer?
PDF のページ数を取得する
16 17 18 19 20 21 22 |
# File 'lib/vivlio/starter/cli/pdf/standard_provider.rb', line 16 def page_count(pdf_path) return nil unless File.exist?(pdf_path) ::PDF::Reader.new(pdf_path).page_count rescue StandardError nil end |
#stamp_nombre!(original_pdf_path, bleed_pt: 3.0 * (72.0 / 25.4)) ⇒ Boolean
入稿用 PDF に隠しノンブルを書き込む
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/vivlio/starter/cli/pdf/standard_provider.rb', line 40 def stamp_nombre!(original_pdf_path, bleed_pt: 3.0 * (72.0 / 25.4)) # --- Phase: Validation --- unless File.exist?(original_pdf_path) CLI::Common.log_warn("[NombreStamper] PDF が見つかりません: #{original_pdf_path}") return false end total_pages = page_count(original_pdf_path) || 0 return false if total_pages.zero? # --- Phase: Preparation --- CLI::Common.log_action("[NombreStamper] 隠しノンブルを書き込みます(#{total_pages} ページ)[MIT Mode]…") nombre_pdf_path = "#{original_pdf_path}.nombre.pdf" # --- Phase: Generate & Merge --- create_nombre_pdf(nombre_pdf_path, original_pdf_path, bleed_pt) merge_nombre(original_pdf_path, nombre_pdf_path) # --- Phase: Cleanup --- FileUtils.rm_f(nombre_pdf_path) CLI::Common.log_success("[NombreStamper] 隠しノンブル書き込み完了(#{total_pages} ページ)") true rescue StandardError => e CLI::Common.log_error("[NombreStamper] 隠しノンブル書き込みに失敗: #{e.}") false end |