我正在用回形针上传一个pdf文件到s3。我想对上传的pdf文件应用密码保护。
我尝试使用问题中给出的代码如何用Ruby编辑或编写现有的PDF ?!编辑现有的PDF文件(回形针使用的TMP文件)并尝试使用
应用密码保护Prawn::Document.generate("tmp/abc.pdf",:template => params[:ebook].path) do encrypt_document(:user_password => 'foo', :owner_password => 'bar',
:permissions => { :print_document => false,
:modify_contents => false,
:copy_contents => false,
:modify_annotations => false } end
模板支持在prawn中是否仍然存在,或者它已经被弃用了,因为我在prawn手册中没有找到任何关于模板的内容!
?是否有其他方法或任何其他宝石来做到这一点?
谢谢。
template
在0.13.0
版本中被移除,因为它太bug了:
对模板的支持在Prawn 0.13.0中被删除,在0.14.0中默认禁用,并在0.15.0中被提取。
此gem包含提取的模板代码,它完全不受支持,但提供了Prawn 0.12.0中多年的旧功能。
来源:https://github.com/prawnpdf/prawn-templates
正如他所说,你可以尝试将库添加到当前的Prawn安装中。
否则,您可以使用pdftk
与Open3
模块(http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/):
require 'open3'
file_name = 'hello_world_1.pdf' # input
file_name_output = 'hello_world_2.pdf' # output
usr = 'foo'
pwd = 'bar'
pdftek = './pdftk.exe' # tested on windows
Open3.popen3("#{pdftek} #{file_name} output #{file_name_output} owner_pw #{pwd} user_pw #{usr}") do |stdin,stdout,stderr|
# ...
end
还有一个ruby的包装器,但我还没有测试:https://github.com/tcocca/active_pdftk