rubypdfprawn

Replace some text in a PDF template using Prawn in Ruby


I am generating a PDF in Prawn using a template using code similar to:

Prawn::Document.new(:template => "template.pdf")

This works great, and I can add to the document in the normal way - however I would like to search for and replace some text that gets added from the template. Is this possible with Prawn?

Looking at the Prawn code it does the following:

 if options[:template]
   fresh_content_streams(options)
   go_to_page(1)
 else
   .....
 end

 .....

 # adds a new, empty content stream to each page. Used in templating so
 # that imported content streams can be left pristine
 #
 def fresh_content_streams(options={})
   .....
 end

So it creates a new content stream to prevent changing the data given in the template - the question is can I look into and change the existing stream with Prawn?


Solution

  • I asked about this at Github here. Apparently it is not possible, and is a lot more complex than I realized.