Class: VivlioStarter::Pdf::StandardProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/vivlio_starter/cli/pdf/standard_provider.rb

Overview

MITライセンス互換の標準プロバイダ

隠しノンブルの合成は本体(Build::NombreStamper: Prawn + qpdf --overlay)へ移設したため、 プロバイダの責務は「ページ数取得・空白ページ生成・アウトライン付与」に縮小した。 拡張プラグイン(vivlio-starter-pdf / HexaPDF)が担うのはアウトライン付与のみ。

Instance Method Summary collapse

Instance Method Details

#add_outline!(_original_pdf_path, _items, max_level:) ⇒ Boolean

PDF アウトラインを付与する (Standard モードではスキップ)

Parameters:

  • original_pdf_path (String)

    対象のPDFファイルパス

  • items (Array<Hash>)

    アウトラインの項目配列

  • max_level (Integer)

    最大階層

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/vivlio_starter/cli/pdf/standard_provider.rb', line 43

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を生成する

Parameters:

  • path (String)

    出力先PDFファイルのパス

  • width_pt (Float)

    ページの幅 (pt)

  • height_pt (Float)

    ページの高さ (pt)

Returns:

  • (String)

    出力先PDFファイルのパス



31
32
33
34
35
36
# File 'lib/vivlio_starter/cli/pdf/standard_provider.rb', line 31

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 のページ数を取得する

Parameters:

  • pdf_path (String)

    対象PDFファイルのパス

Returns:

  • (Integer, nil)

    ページ数、取得失敗時は nil



18
19
20
21
22
23
24
# File 'lib/vivlio_starter/cli/pdf/standard_provider.rb', line 18

def page_count(pdf_path)
  return nil unless File.exist?(pdf_path)

  ::PDF::Reader.new(pdf_path).page_count
rescue StandardError
  nil
end