prawn-templates icon indicating copy to clipboard operation
prawn-templates copied to clipboard

Is it possible to render content behind the template page?

Open brandoncc opened this issue 4 years ago • 3 comments

I need to render an image behind the content from the template. Is that possible?

brandoncc avatar May 24 '20 22:05 brandoncc

It is possible in general but prawn-template doesn't currently implement it as far as I can tell.

gettalong avatar May 25 '20 11:05 gettalong

Do you happen to have any pointers how I can make it happen? I'm not very familiar with how the child tree works, or how to insert at the top of it.

Thanks!

On Mon, May 25, 2020, 4:28 AM Thomas Leitner [email protected] wrote:

It is possible in general but prawn-template doesn't currently implement it as far as I can tell.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/prawnpdf/prawn-templates/issues/27#issuecomment-633525814, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAEEZZJ7K6SCMYDSBQSOW2TRTJI6FANCNFSM4NJCMINQ .

brandoncc avatar May 26 '20 06:05 brandoncc

So have a look at https://github.com/prawnpdf/prawn-templates/blob/master/lib/pdf/core/page.rb#L29-L41

This is where two additional content streams (a page can have zero, one or more content streams representing the contenst) are added to the page:

  • The first is added before the current content stream, i.e. the contents of the existing page, containing just one instruction for saving the graphics state.
  • The second is added after the current content stream, restoring the graphics state so that Prawn has a pristine version of the graphics state to start.

What you need to do is modify the first content stream to not only save the graphics state as last instruction but also draw the image you want.

As far as to what the best way for this to accomplish would be, it depends on whether this should work just for the one case you have in mind or in a general way.

gettalong avatar May 26 '20 07:05 gettalong