You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Prawn template feature is really awesome, however - I am wondering if it is possible to change some text added by using a template. I'm happy to do some of the work if anybody could point me in the right direction...
Looking at the code, when initializing the document - if there is a template passed it calls fresh_content_streams in internals.rb, which has this comment:
# adds a new, empty content stream to each page. Used in templating so# that imported content streams can be left pristine
Can I get to the imported content streams, and change them (then write a new document)? Appreciate any pointers.
Just to be clear, I am making a new document with a template PDF. In this PDF it has the text "foo", I want to replace it (in the same place, font etc.) with "bar" then save a new PDF.
The text was updated successfully, but these errors were encountered:
Sadly, this is not possible to do robustly with Prawn, because the PDF specification operates at a lower level than the level you want to work at.
A bit of a technical background: PDF text is drawn by the use of character codes, which identify glyphs but not necessarily Unicode characters. There is a provision in the PDF spec for fonts to include a mapping from character IDs to Unicode, but it is optional. So even the problem of identifying "this page contains the text foo" is nontrivial at best and impossible to accomplish for arbitrary compliant PDFs. The rest of the process (replacing text) has similar technical difficulties if we would want to create a completely compliant solution.
So I think the best solution for you is going to depend on where these template PDFs are going to come from. If they are being generated by Prawn, you may be able to defer the processing until you have the data you need. If they are coming from somewhere else, you'll probably have to measure distances and draw text on top of the template. It's a semi-manual process, but it has worked for me several times in the past. Hope this helps!
Hi,
The Prawn template feature is really awesome, however - I am wondering if it is possible to change some text added by using a template. I'm happy to do some of the work if anybody could point me in the right direction...
Looking at the code, when initializing the document - if there is a template passed it calls fresh_content_streams in internals.rb, which has this comment:
Can I get to the imported content streams, and change them (then write a new document)? Appreciate any pointers.
Just to be clear, I am making a new document with a template PDF. In this PDF it has the text "foo", I want to replace it (in the same place, font etc.) with "bar" then save a new PDF.
The text was updated successfully, but these errors were encountered: