Class: Utilities::PdfSplitter
- Inherits:
-
BaseService
- Object
- BaseService
- Utilities::PdfSplitter
- Defined in:
- app/services/utilities/pdf_splitter.rb
Instance Method Summary collapse
-
#process(pdf_path, output_directory: nil) ⇒ Object
Splits a pdf into individual pages, if an output directory is specified the splitted files are outputted there, otherwise a temporary file is used Please note that temporary files are automatically cleaned when ruby exits or the class is garbage collected.
Instance Method Details
#process(pdf_path, output_directory: nil) ⇒ Object
Splits a pdf into individual pages, if an output directory is specified the
splitted files are outputted there, otherwise a temporary file is used
Please note that temporary files are automatically cleaned when ruby exits
or the class is garbage collected
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/utilities/pdf_splitter.rb', line 6 def process(pdf_path, output_directory: nil) output_directory ||= Dir.tmpdir() master_pdf = PdfCombinator.new master_pdf.load(pdf_path) return [pdf_path] if master_pdf.pages.size == 1 i = 0 pdf_paths = [] master_pdf.pages.each do |pdf_page| pdf = PdfCombinator.new pdf << pdf_page file_base_name = File.basename(pdf_path, '.pdf') file_path_out = nil file_path_out = "#{output_directory}/#{file_base_name}_#{i}.pdf" pdf.save file_path_out pdf_paths << file_path_out i += 1 end pdf_paths end |