8

-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:

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.

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?

-May the force be with you.

Sandeep
  • 223
  • 3
  • 5

3 Answers3

3

You can't. Prawn is for writing PDFs, not reading them.

Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
2

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

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.

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.

Mark Storer
  • 15,672
  • 3
  • 42
  • 80
  • +1 Agreed. PDF's are for not for content generation or editing they are for layout control. Just open one up in a raw text editor and you'll see what Mark means. They are full of gobbledygook and other such gibberish. –  Feb 02 '11 at 02:11
  • The main thing is getting the text in a predetermined location on each page - like a footer(empty spot). {galaxy} doesn't even have to be present. So no problems drawing the box and placing the text. I'm just wondering if this is possible with an existing PDF. And if so how to accomplish this task with Prawn PDF. @$!#$ I hear Imperial Storm Troopers...this location has been compromised. – Sandeep Feb 02 '11 at 03:34
  • You gave it your best shot! - May the force be with you. – Sandeep Feb 05 '11 at 21:06
0

Late and around, but in Ruby you can call Applidok PDF merge, which allow to write user data (e.g. from a Web form) on any existing PDF. See Ruby doc: http://doc.applidok.com/merge-ruby.html .

cchantep
  • 9,118
  • 3
  • 30
  • 41