Class: StackedPdfGenerator::Generator
- Inherits:
-
Object
- Object
- StackedPdfGenerator::Generator
- 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
-
#autoscale ⇒ Object
readonly
Returns the value of attribute autoscale.
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#crop_box_mm ⇒ Object
readonly
Returns the value of attribute crop_box_mm.
-
#crop_from_marks ⇒ Object
readonly
Returns the value of attribute crop_from_marks.
-
#input_path ⇒ Object
readonly
Returns the value of attribute input_path.
-
#mark_edge_tolerance_mm ⇒ Object
readonly
Returns the value of attribute mark_edge_tolerance_mm.
-
#mark_max_length_mm ⇒ Object
readonly
Returns the value of attribute mark_max_length_mm.
-
#output_path ⇒ Object
readonly
Returns the value of attribute output_path.
-
#pages_per_sheet ⇒ Object
readonly
Returns the value of attribute pages_per_sheet.
-
#paper_size ⇒ Object
readonly
Returns the value of attribute paper_size.
-
#portrait ⇒ Object
readonly
Returns the value of attribute portrait.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#sheet_margins_raw ⇒ Object
readonly
Returns the value of attribute sheet_margins_raw.
-
#two_sided_flipped ⇒ Object
readonly
Returns the value of attribute two_sided_flipped.
Instance Method Summary collapse
- #call ⇒ Object
-
#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
constructor
A new instance of Generator.
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
#autoscale ⇒ Object (readonly)
Returns the value of attribute autoscale.
30 31 32 |
# File 'lib/stacked_pdf_generator.rb', line 30 def autoscale @autoscale end |
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
30 31 32 |
# File 'lib/stacked_pdf_generator.rb', line 30 def columns @columns end |
#crop_box_mm ⇒ Object (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_marks ⇒ Object (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_path ⇒ Object (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_mm ⇒ Object (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_mm ⇒ Object (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_path ⇒ Object (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_sheet ⇒ Object (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_size ⇒ Object (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 |
#portrait ⇒ Object (readonly)
Returns the value of attribute portrait.
30 31 32 |
# File 'lib/stacked_pdf_generator.rb', line 30 def portrait @portrait end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
30 31 32 |
# File 'lib/stacked_pdf_generator.rb', line 30 def rows @rows end |
#sheet_margins_raw ⇒ Object (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_flipped ⇒ Object (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
#call ⇒ Object
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.) ensure cleanup_tempfiles end |