Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>---------- UPDATED ANSWER --------</p> <p>The previous workaround wasn't good enough for the production server, so I had to use development version from git repo installed as a submodule under vendor/prawn, as described here: <a href="https://github.com/sandal/prawn/wiki/Using-Prawn-in-Rails" rel="nofollow">https://github.com/sandal/prawn/wiki/Using-Prawn-in-Rails</a></p> <p>The memory issue with the group method is gone, but the syntax/options for things have changed somewhat. So I had to rewrite the code to generate PDF.</p> <p>Also, getting the submodule to play nicely with the git repo for the Rails app is difficult. Deployment to production was tough.</p> <p>---------- ORIGINAL ANSWER --------</p> <p>This isn't a fix, but it makes the problem take a few more group iterations before it manifests itself:</p> <ul> <li>override the Prawn::Document instance method named 'group'</li> <li>use the code from the 'group' function from the newest development version of prawn (from github.com)</li> </ul> <p>The way I did this is that I added a file to the /lib folder of my Rails app. This file will include the Prawn gems and defined the mime type for a PDF document:</p> <pre><code>class PdfPrawn require 'prawn' require 'prawn/core' require 'prawn/table' MIME_TYPE = "application/pdf" end class Prawn::Document def group(second_attempt=false) old_bounding_box = @bounding_box @bounding_box = SimpleDelegator.new(@bounding_box) def @bounding_box.move_past_bottom raise RollbackTransaction end success = transaction { yield } @bounding_box = old_bounding_box unless success raise Prawn::Errors::CannotGroup if second_attempt old_bounding_box.move_past_bottom group(second_attempt=true) { yield } end success end end </code></pre> <p>And then in a model file, I define a method to generate my PDF and use something like this:</p> <pre><code>def to_pdf require "#{File.expand_path(RAILS_ROOT)}/lib/pdf_prawn" pdf = Prawn::Document.new # code to add stuff to PDF pdf.render end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload