Sha256: bc7fce04baf44f6daad725d5b2dd5f7708d2486fd9eb3c2d4aad8ca531faf84e

Contents?: true

Size: 829 Bytes

Versions: 9

Compression:

Stored size: 829 Bytes

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 = File.join(@output, "#{pdf_name}_%d.pdf")
        FileUtils.mkdir_p @output unless File.exists?(@output)
        cmd = "pdftk #{pdf} burst output #{page_path} 2>&1"
        result = `#{cmd}`.chomp
        FileUtils.rm('doc_data.txt') if File.exists?('doc_data.txt')
        raise ExtractionFailed, result if $? != 0
        result
      end
    end


    private

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

  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
docsplit-0.5.2 lib/docsplit/page_extractor.rb
docsplit-0.5.1 lib/docsplit/page_extractor.rb
docsplit-0.5.0 lib/docsplit/page_extractor.rb
docsplit-0.4.1 lib/docsplit/page_extractor.rb
docsplit-0.4.0 lib/docsplit/page_extractor.rb
docsplit-0.3.4 lib/docsplit/page_extractor.rb
docsplit-0.3.3 lib/docsplit/page_extractor.rb
docsplit-0.3.1 lib/docsplit/page_extractor.rb
docsplit-0.3.0 lib/docsplit/page_extractor.rb