title: Printing a pdf of more than 5000 pages takes longtime using Prawn pdf gem
body: <p>I am using prawn pdf gem to print pdf. </p>
  
  <p>I am formatting the data in to tables and then printing it to the pdf. I have around 5000 pages (about 50000 entries) to print and it takes forever. For small number of pages its quick ... Is there any way I can improve the speed of printing. </p>
  
  <p>Also, printing without the data in table format was quick. please help me out with this.</p>
  
  <p>code for this : </p>
  
  <pre><code>format.pdf {
  
      pdf = Prawn::Document.new(:margin =&gt; [20,20,20,20])
      pdf.font "Helvetica"
      pdf.font_size 12
  
      @test_points_all = Hash.new
      dataset_id = Dataset.where(collection_success: true).order('created_at DESC').first
  
      if(inode.leaf?)
          meta=MetricInstance.where(dataset_id: dataset_id, file_or_folder_id: inode.id).includes(:test_points,:file_or_folder,:dataset).first
          @test_points_all[inode.name] =  meta.test_points                 
      else
          nodes2 = []
          nodes2 = inode.leaves
  
          if(!nodes2.nil?)
              nodes2.each do |node|
                  meta=MetricInstance.where(dataset_id: dataset_id, file_or_folder_id: node.id).includes(:test_points,:file_or_folder,:dataset).first
                  @test_pointa = meta.test_points
                  if(!@test_pointa.nil?)
                      @test_points_all[node.name] = @test_pointa
                  end
              end    
          end
      end
  
      @test_points_all.each do |key, points|
          table_data = [["&lt;b&gt; #{key} &lt;/b&gt;", "&lt;b&gt;433&lt;b&gt;","xyz","xyzs"]]
          points.each do |test|
              td=TestDescription.find(:first, :conditions=&gt;["test_point_id=?", test.id])
  
              if (!td.nil?)
                 table_data &lt;&lt; ["#{test.name}","#{td.header_info}","#{td.comment_info}","#{td.line_number}"]
              end
  
              pdf.move_down(5)
              pdf.table(table_data, :width =&gt; 500, :cell_style =&gt; { :inline_format =&gt; true ,:border_width =&gt; 0}, :row_colors =&gt; ["FFFFFF", "DDDDDD"]) 
  
              pdf.text ""
  
              pdf.stroke do
                  pdf.horizontal_line(0, 570)
              end
  
              pdf.move_down(5)
          end
      end
  
  
      pdf.number_pages("&lt;page&gt; of &lt;total&gt;", {
                      :start_count_at =&gt; 1,
                      :page_filter =&gt; lambda{ |pg| pg &gt; 0 },
                      :at =&gt; [pdf.bounds.right - 50, 0],
                      :align =&gt; :right,
                      :size =&gt; 9
                    })
  
      pdf.render_file File.join(Rails.root, "app/reports", "x.pdf")
      filename = File.join(Rails.root, "app/reports", "x.pdf")
      send_file filename, :filename =&gt; "x.pdf", :type =&gt; "application/pdf",:disposition =&gt; "inline"
  end
  </code></pre>