Class: StackedPdfGenerator::Generator

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

Overview

Performs the heavy lifting: validates inputs, shells out to pdfjam/podofocrop, and sequences pages via stacking-order to build the final PDF.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_path:, output_path:, paper_size:, autoscale:, portrait:, rows: nil, columns: nil, pages_per_sheet: nil, sheet_margins: nil, two_sided_flipped: false, crop_from_marks: false, crop_box: nil, mark_max_length_mm: nil, mark_edge_tolerance_mm: nil) ⇒ Generator

Returns a new instance of Generator.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/stacked_pdf_generator.rb', line 34

def initialize(input_path:, output_path:, paper_size:, autoscale:, portrait:, rows: nil, columns: nil,
               pages_per_sheet: nil, sheet_margins: nil, two_sided_flipped: false,
               crop_from_marks: false, crop_box: nil,
               mark_max_length_mm: nil, mark_edge_tolerance_mm: nil)
  @input_path = input_path
  @output_path = output_path
  @paper_size = paper_size.to_s.upcase
  @autoscale = autoscale.to_s
  @portrait = boolean_cast(portrait)
  @sheet_margins_raw = sheet_margins
  @rows = rows.nil? ? nil : Integer(rows)
  @columns = columns.nil? ? nil : Integer(columns)
  @pages_per_sheet = pages_per_sheet.nil? ? nil : Integer(pages_per_sheet)
  @two_sided_flipped = boolean_cast(two_sided_flipped)
  @crop_from_marks = boolean_cast(crop_from_marks)
  @crop_box_mm = crop_box # hash {top:, bottom:, left:, right:} in mm, optional
  @mark_max_length_mm = mark_max_length_mm
  @mark_edge_tolerance_mm = mark_edge_tolerance_mm
  normalize_layout_dimensions!
end

Instance Attribute Details

#autoscaleObject (readonly)

Returns the value of attribute autoscale.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def autoscale
  @autoscale
end

#columnsObject (readonly)

Returns the value of attribute columns.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def columns
  @columns
end

#crop_box_mmObject (readonly)

Returns the value of attribute crop_box_mm.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def crop_box_mm
  @crop_box_mm
end

#crop_from_marksObject (readonly)

Returns the value of attribute crop_from_marks.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def crop_from_marks
  @crop_from_marks
end

#input_pathObject (readonly)

Returns the value of attribute input_path.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def input_path
  @input_path
end

#mark_edge_tolerance_mmObject (readonly)

Returns the value of attribute mark_edge_tolerance_mm.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def mark_edge_tolerance_mm
  @mark_edge_tolerance_mm
end

#mark_max_length_mmObject (readonly)

Returns the value of attribute mark_max_length_mm.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def mark_max_length_mm
  @mark_max_length_mm
end

#output_pathObject (readonly)

Returns the value of attribute output_path.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def output_path
  @output_path
end

#pages_per_sheetObject (readonly)

Returns the value of attribute pages_per_sheet.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def pages_per_sheet
  @pages_per_sheet
end

#paper_sizeObject (readonly)

Returns the value of attribute paper_size.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def paper_size
  @paper_size
end

#portraitObject (readonly)

Returns the value of attribute portrait.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def portrait
  @portrait
end

#rowsObject (readonly)

Returns the value of attribute rows.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def rows
  @rows
end

#sheet_margins_rawObject (readonly)

Returns the value of attribute sheet_margins_raw.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def sheet_margins_raw
  @sheet_margins_raw
end

#two_sided_flippedObject (readonly)

Returns the value of attribute two_sided_flipped.



30
31
32
# File 'lib/stacked_pdf_generator.rb', line 30

def two_sided_flipped
  @two_sided_flipped
end

Instance Method Details

#callObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/stacked_pdf_generator.rb', line 55

def call
  validate_arguments!
  apply_crop_from_marks if crop_pre_processing?
  run_pdfjam
  finalize_output
  Result.new(success?: true, message: '')
rescue ProcessingError => e
  Result.new(success?: false, message: e.message)
ensure
  cleanup_tempfiles
end