Sha256: 10cd704b989baa8fe35a62241a97a197acc4e0c1504f786420c309e99b13f0eb

Contents?: true

Size: 646 Bytes

Versions: 1

Compression:

Stored size: 646 Bytes

Contents

require 'hexapdf'
require 'open-uri'

module AlegoPdf
  class Merging
    attr_reader :filepaths, :filename

    def initialize(filepaths, filename)
      @filepaths = filepaths
      @filename = filename
    end

    def call
      target = HexaPDF::Document.new

      filepaths.each do |filepath|
        uri = URI.parse(filepath).open(&:read)
        tempfile = Tempfile.new
        tempfile.write(uri.force_encoding('UTF-8'))
        tempfile.close

        pdf = HexaPDF::Document.open(tempfile)
        pdf.pages.each { |page| target.pages << target.import(page) }
      end

      target.write(filename, optimize: true)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alego_pdf-1.0.0 lib/alego_pdf/merging.rb