我正在开发 Rails 应用程序 (Rails 3.1),并且能够上传 PDF 文件。其他用户登录后就可以下载 PDF 文件。
我真正想做的是将当前登录用户的用户名附加到每个 PDF 页面的底部。因此,PDF 中每个页面的底部都是这样的:
Downloaded from ww.mysite.com by Mr U. Name
我知道如何使 Rails 从视图中输出 pdf(根据一些教程),但我从未需要更改已上传的 PDF。
旁注:PDF 文件将从 Powerpoint 和/或 Keynote 输出 - 因此每个页面都是一张“幻灯片”。
I am working on a Rails application (Rails 3.1) and have the ability to upload a PDF file. The PDF file can then be downloaded by other users once they have logged in.
What I would really like to do is append the username of the current logged in user to the bottom of every one of the PDF pages. So at the bottom of every page in the PDF would be something like:
Downloaded from ww.mysite.com by Mr U. Name
I know how to make rails output a pdf from a view (as per a few tutorials), but I have never had to alter a PDF that has already been uploaded.
Side note: the PDF files are going to be outputs from Powerpoint and/or Keynote - so each page is a 'slide'.
发布评论
评论(1)
纯 ruby 解决方案是不存在的,但我一直在使用 python 脚本进行相同类型的操作(将打印标记添加到现有 PDF),使用 pyPdf 和 pycairo。
您可以在 Github 上找到它,大部分代码位于 draw-outline.py 和 outline.py。
如果您对此解决方案感兴趣,我可以提取一个快速教程并将其发布在这里。
更新
我提取了一个快速脚本,可以将文本添加到任意 PDF 的每一页,它既快速又脏,但应该可以完成工作。
用法:
代码:
The pure ruby solutions are non-existent, but I've been doing the same kind of manipulation (adding print marks to an existing PDF) with a python script, using pyPdf and pycairo.
You can find it on Github, the bulk of the code is in draw-outline.py and outline.py.
I can extract a quick tutorial and post it here if you're interested by this solution.
Update
I've extracted a quick script to add text to every page of an arbitrary PDF, it's quick and dirty but it should do the job.
Usage:
Code: