module RemovePdfRestrictions

Constants

VERSION

Public Class Methods

execute!(file_name) click to toggle source
# File lib/remove_pdf_restrictions.rb, line 7
def self.execute!(file_name)
  tmp_file = SecureRandom.uuid
  File.rename(file_name, tmp_file)
  begin
    `gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=#{file_name} -c .setpdfwrite -f #{tmp_file}`
    FileUtils.rm(tmp_file)
  rescue => e
    File.rename(tmp_file, file_name)
    raise e
  end
end