When compress flag is set to true the document does not render the template #308

hilios opened this Issue Dec 19, 2011 · 9 comments


None yet
5 participants

hilios commented Dec 19, 2011

This issue is happening with prawn 1.0.0.rc1

To reproduce just start a new Prawn::Document with some pdf template and compress flag setted to true. When you render the pdf only the text or shapes that you create whitin are rendered to stage.

The same issue occours when you start_new_page inside the document.

To reproduce just do the following:

def to_pdf
  # Build the pdf
  pdf = Prawn::Document.new :template => 'doc_template.pdf', :compress => true do
    text "Only me here on the first page"
    start_new_page(:template => 'page_template.pdf')
    text "Again no page template"

I can confirm this issue too


yob commented Dec 8, 2012

Thanks for this report, this seems to be fixed on master.

@yob yob closed this Dec 8, 2012


mojavelinux commented Dec 26, 2013

I'm still seeing this problem with 0.13.1 and HEAD if there is an image on the template page.


practicingruby commented Dec 26, 2013

Hi @mojavelinux,

Sorry that this isn't fixed. Unfortunately we're dropping support for templates because we don't have anyone with the experience and time necessary to maintain them.

This was mentioned in the 0.13 release notes and is also now mentioned in the manual, but the code will be at least disabled in time for the 0.14 release, and removed by 0.15. If I have time to do it, I'll extract the code into an (unsupported) gem extension that hopefully someone will be willing to maintain or improve in time, but for now we need to focus on Prawn as a whole and have very limited time to do so.


mojavelinux commented Dec 26, 2013

What's the reason support is being dropped? I mean, except for the compress issue, it works. I find it useful for being able to merge PDF documents to weave dynamic pages into a static boilerplate document.

Btw, you can reproduce by adding 'complex_template.rb' to the manual/templates directory with the following code:

require File.expand_path(File.join(File.dirname(__FILE__),
                                   %w[.. example_helper]))

filename = "#{Prawn::DATADIR}/pdfs/complex_template.pdf"

Prawn::Example.generate("complex_template.pdf", :template => filename, :compress => true) do


  text "Previous pages and content imported.", :align => :center
  text "This page and content is brand new.",  :align => :center

mojavelinux commented Dec 26, 2013

Another way to ask the question, is there an alternative way to use Prawn to weave new pages into an existing PDF? I'm not that interested in modifying the pages I import (otherwise, I would just create them from scratch).


practicingruby commented Dec 26, 2013

@mojavelinux There is a long conversation on the mailing list about this, and although the only thing that might be broken in templates for your use case is compression, other user are having many more issues with them. See the full list here (even though they are closed, they are unresolved):


I asked for help with addressing those issues in late November, but not one of them has been fixed yet, even though some research effort was put in.

The good news is that for your particular case, you can probably use the pdftk command line tool to join PDFs together. Some examples are here: http://www.pdflabs.com/docs/pdftk-cli-examples/

Also worth considering is adding this sort of read-only template behavior to Prawn... it's not what everyone wants, but at least a decent number of users will have a similar use case to your own.

@cheba, @yob -- how realistic would it be to add read-only page merging to Prawn, and would it allow us to maintain a high level of stability, or would it still be brittle?


mojavelinux commented May 5, 2014

Thanks for the reply @sandal. What I ended up doing was using GhostScript 9.10 to optimize the PDF after Prawn generates it. The quality of the optimized PDF is quite acceptable and seems to be the right solution for my needs. Here's the optimize script I wrote:



mojavelinux commented May 5, 2014

Although I like pdftk a lot, the reason I can't use it in my case is because I need the imported pages to occupy space when I'm creating the document. Granted, I could leave blank pages and then swap in the real pages in a postprocessing step, but it's much more convenient to do that in the main script. But that might be besides the point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment