如何使用Ruby Prawn替换现有PDF中的单词? [英] How to replace a word in an existing PDF using Ruby Prawn?

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

问题描述

-您好,Sandeep在这里.我是绝地大师尤达的学徒.我的主人相信Ruby社区中的力量很强大,因此选择我来完成一个使用Ruby语言的简单任务:

-Hello Sandeep here. I am an apprentice to the Jedi Master Yoda. My master believes the force is strong in the Ruby community and has chosen me for a simple task to complete using the Ruby langauge:

我需要使用Prawn PDF gem来完成任务.我有一个名为Dooku.pdf的现有pdf文档-它包含有关Evil Count Dooku活动的敏感信息.在Dooku.pdf中,有一个名为{galaxy}的文本. {galaxy}始终位于pdf文档的每一页上的同一位置.

I need to use the Prawn PDF gem to accomplish the task. I have an existing pdf document called Dooku.pdf - it contains sensitive information on the Evil Count Dooku's activities. In Dooku.pdf there is text called {galaxy}. {galaxy} is always in the same location on every page of the pdf document.

我需要打开Dooku.pdf,用{planet}替换{galaxy}的每个实例,然后保存/关闭Dooku.pdf.如何使用Prawn PDF gem完成此任务?

I need to open Dooku.pdf, replace each instance of {galaxy} with {planet} and then save/close Dooku.pdf. How do I accomplish this task using the Prawn PDF gem?

-愿力量与您同在.

推荐答案

1)我是所有星球大战的粉丝,但该死.

1) I'm a star wars fan and all, but damn.

2)您的简单任务"甚至远非简单.覆盖现有文本并不难...但是完全替换它是另一个问题.并忘记重排现有文本.一切皆有可能.

2) Your "simple task" is not even remotely simple. It's not that hard to COVER the existing text... but REPLACING IT is another mater entirely. And forget reflowing existing text. All-but-impossible.

如果覆盖它就足够了,那么您只需要在第一个字符串上绘制一个填充有背景色的矩形,然后在其顶部绘制第二个字符串即可.我不熟悉Prawn PDF,因此将实现细节留给读者练习.

If covering it will suffice, then you need only draw a rectangle filled with the background color over your first string, then draw your second string on top of it. I'm not familiar with Prawn PDF, so I'll leave the implementation details as an Exercise For the Reader.

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

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