Sha256: 75e7b4f6dedb9b3b15ca5cbeea343d929a48e41bc335cdaebf54cdf2d3bad926

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Docsplit
  # Delegates to **pdftk** in order to create bursted single pages from
  # a PDF document.
  class PageExtractor
    # Burst a list of pdfs into single pages, as `pdfname_pagenumber.pdf`.
    def extract(pdfs, opts)
      extract_options opts
      [pdfs].flatten.each do |pdf|
        pdf_name = File.basename(pdf, File.extname(pdf))
        page_path = ESCAPE[File.join(@output, pdf_name.to_s)] + '_%d.pdf'
        FileUtils.mkdir_p @output unless File.exist?(@output)

        cmd = if DEPENDENCIES[:pdftailor] # prefer pdftailor, but keep pdftk for backwards compatability
                "pdftailor unstitch --output #{page_path} #{ESCAPE[pdf]} 2>&1"
              else
                "pdftk #{ESCAPE[pdf]} burst output #{page_path} 2>&1"
        end
        result = `#{cmd}`.chomp
        FileUtils.rm('doc_data.txt') if File.exist?('doc_data.txt')
        raise ExtractionFailed, result if $?.exitstatus.nonzero?
        result
      end
    end

    private

    def extract_options(options)
      @output = options[:output] || '.'
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
burisu-docsplit-0.7.9 lib/docsplit/page_extractor.rb