Created
April 19, 2013 18:04
-
-
Save alex-kovshovik/5422059 to your computer and use it in GitHub Desktop.
This works to concatenate PDFs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This class uses the pdftk toolkit. | |
class PdfToolkit | |
# Merges some pdf files to output file | |
# | |
# options | |
# :from_files - array of source pdf files | |
# :to_file - output file | |
# | |
def self.merge(options) | |
command = "\"#{options[:from_files].join('" "')}\" cat output \"#{options[:to_file]}\"" | |
run(command) | |
end | |
# Fills pdf data in pdf form and creates output file | |
# | |
# options | |
# :form_file - pattern file | |
# :data_file - file with form data | |
# :to_file - output file | |
# :flatten - if true then document will be made readonly after filling | |
def self.fill_form(options) | |
command = "\"#{options[:form_file]}\" fill_form \"#{options[:data_file]}\" output \"#{options[:to_file]}\" #{"flatten" if options[:flatten]}" | |
run(command) | |
end | |
private | |
# Runs pdftk util. | |
def self.run(command) | |
full_command = "pdftk #{command}" | |
output = %x[ #{full_command} ] | |
return_status = $? | |
if return_status.nil? or return_status.success? != true | |
raise "Running PDFTK tool failed with: #{full_command} / #{output}" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment