如何使用Ruby编辑或编写现有PDF? [英] How to edit or write on existing PDF with Ruby?

查看:131
本文介绍了如何使用Ruby编辑或编写现有PDF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个PDF模板文件,它们内容复杂,并且其中有几个空白区域/区域.我需要能够在这些空白区域中写入文本,并将生成的PDF保存在文件夹中.

I have a couple of PDF template files with complex content and several blank regions/areas in them. I need to be able to write text in those blank regions and save the resulting PDFs in a folder.

我在谷歌上搜索了有关该问题的答案,但是我没有找到确切的答案.更好的解决方案之一是 PDF :: Toolkit ,但这需要购买Adobe Acrobat才能添加现有PDF文档的可替换属性.

I googled for answers on this question quite intensively, but I didn't find definite answers. One of the better solutions is PDF::Toolkit, but it would require the purchase of Adobe Acrobat to add replaceable attributes to existing PDF documents.

PHP世界受到 FPDI 的祝福.只需打开一个PDF文件并在现有内容上进行书写/绘图即可.有一个该库的Ruby端口,但最后一次提交发生在2009年初另外,该项目看起来并没有得到广泛使用和支持.

The PHP world is blessed with FPDI that can be used to simply open a PDF file and write/draw on it over the existing content. There is a Ruby port of this library, but the last commit for it happened at the beginning of 2009. Also that project doesn't look like it is widely used and supported.

问题是:什么是在现有PDF上进行编辑,编写或绘图的更好Ruby方法?

The question is: What is the better Ruby way of editing, writing or drawing on existing PDFs?

这个问题似乎在这里也没有得到回答.这些问题是相关的,但并非完全相同:

This question also doesn't seem to be answered on here. These questions are related, but not really the same:

  • Prawn gem: How to create the .pdf from an *existing* file (.xls)
  • watermark existing pdf with ruby
  • Ruby library for manipulating existing PDF
  • How to replace a word in an existing PDF using Ruby Prawn?

推荐答案

您一定要签出大虾 gem,通过它您可以生成任何自定义pdf文件.通过将现有的PDF视为新的Prawn文档的模板,您实际上可以使用对虾将文本写入到现有的pdf中.

you have to definitely check out Prawn gem, by which you can generate any custom pdf files. You can actually use prawn to write in text into existing pdfs by treating the existing PDF as a template for your new Prawn document.

例如:

filename = "#{Prawn::DATADIR}/pdfs/multipage_template.pdf"
Prawn::Document.generate("full_template.pdf", :template => filename) do
  text "THis content is written on the first page of the template", :align => :center
end

这会将文本写到旧pdf的第一页上.

This will write text onto the first page of the old pdf.

在此处查看更多信息: http://prawn.majesticseacreature.com/manual.pdf

See more here: http://prawn.majesticseacreature.com/manual.pdf

这篇关于如何使用Ruby编辑或编写现有PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆