Class: Sakusei::PdfConcatenator

Inherits:
Object
  • Object
show all
Defined in:
lib/sakusei/pdf_concat.rb

Overview

Concatenates multiple PDF files

Constant Summary collapse

MACOS_JOIN_TOOL =

macOS built-in PDF join tool (last resort fallback)

'/System/Library/Automator/Combine PDF Pages.action/Contents/MacOS/join'

Instance Method Summary collapse

Constructor Details

#initialize(files, output_path) ⇒ PdfConcatenator

Returns a new instance of PdfConcatenator.



9
10
11
12
# File 'lib/sakusei/pdf_concat.rb', line 9

def initialize(files, output_path)
  @files = files.map { |f| File.expand_path(f) }
  @output_path = File.expand_path(output_path)
end

Instance Method Details

#concatObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/sakusei/pdf_concat.rb', line 14

def concat
  validate_files

  # Try tools in order of preference
  if pdfunite_available?
    concat_with_pdfunite
  elsif pdftk_available?
    concat_with_pdftk
  elsif macos_join_available?
    concat_with_macos_join
  else
    raise Error, 'No PDF concatenation tool found. Please install pdfunite (poppler-utils) or pdftk'
  end
end