From d1ece157c699f3e4f40fb5118f7821df83fcb306 Mon Sep 17 00:00:00 2001 From: wvengen Date: Sat, 3 Jan 2015 00:14:38 +0100 Subject: [PATCH] Get rid of last empty page in PDFs --- app/documents/order_by_articles.rb | 4 ++-- app/documents/order_by_groups.rb | 4 ++-- lib/order_pdf.rb | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/documents/order_by_articles.rb b/app/documents/order_by_articles.rb index 59ce509e..a5e50acd 100644 --- a/app/documents/order_by_articles.rb +++ b/app/documents/order_by_articles.rb @@ -12,6 +12,8 @@ class OrderByArticles < OrderPdf def body @order.order_articles.ordered.each do |order_article| + down_or_page + rows = [] dimrows = [] for goa in order_article.group_order_articles.ordered @@ -36,8 +38,6 @@ class OrderByArticles < OrderPdf # dim rows which were ordered but not received dimrows.each { |ri| table.row(ri).text_color = '999999' } end - - down_or_page end end diff --git a/app/documents/order_by_groups.rb b/app/documents/order_by_groups.rb index 68df2134..653ff59c 100644 --- a/app/documents/order_by_groups.rb +++ b/app/documents/order_by_groups.rb @@ -13,6 +13,8 @@ class OrderByGroups < OrderPdf def body # Start rendering @order.group_orders.ordered.each do |group_order| + down_or_page 15 + total = 0 rows = [] dimrows = [] @@ -53,8 +55,6 @@ class OrderByGroups < OrderPdf # dim rows which were ordered but not received dimrows.each { |ri| table.row(ri).text_color = '999999' } end - - down_or_page 15 end end diff --git a/lib/order_pdf.rb b/lib/order_pdf.rb index b636b423..81f2b8d0 100644 --- a/lib/order_pdf.rb +++ b/lib/order_pdf.rb @@ -12,6 +12,7 @@ class OrderPdf < Prawn::Document super(options) @order = order @options = options + @first_page = true end def to_pdf @@ -50,6 +51,10 @@ class OrderPdf < Prawn::Document # add pagebreak or vertical whitespace, depending on configuration def down_or_page(space=10) + if @first_page + @first_page = false + return + end if pdf_add_page_breaks? start_new_page else