--- ev-print-operation.c	2009-05-21 12:27:42.482075936 +0200
+++ ev-print-operation-diff.c	2009-05-21 12:32:39.769436039 +0200
@@ -367,7 +367,7 @@ struct _EvPrintOperationExport {
 	gint n_pages_to_print;
 	gint uncollated_copies;
 	gint collated_copies;
-	gint uncollated, collated, total;
+	gint uncollated, collated, total, skipped;
 
 	gint range, n_ranges;
 	GtkPageRange *ranges;
@@ -676,8 +676,8 @@ export_print_inc_page (EvPrintOperationE
 			find_range (export);
 			export->page = export->start;
 		}
-	} while ((export->page_set == GTK_PAGE_SET_EVEN && export->page % 2 == 0) ||
-		 (export->page_set == GTK_PAGE_SET_ODD && export->page % 2 == 1));
+	} while((export->page_set == GTK_PAGE_SET_EVEN && ( export->page / export->pages_per_sheet ) % 2 == 0) ||
+		(export->page_set == GTK_PAGE_SET_ODD && ( export->page  / export->pages_per_sheet ) % 2 == 1));
 
 	return TRUE;
 }
@@ -875,7 +875,7 @@ export_job_finished (EvJobExport        
 {
 	EvPrintOperation *op = EV_PRINT_OPERATION (export);
 
-	if (export->pages_per_sheet == 1 || export->total % export->pages_per_sheet == 0) {
+	if (export->pages_per_sheet == 1 || (export->total + export->skipped) % export->pages_per_sheet == 0 ) {
 		ev_document_doc_mutex_lock ();
 		ev_file_exporter_end_page (EV_FILE_EXPORTER (op->document));
 		ev_document_doc_mutex_unlock ();
@@ -947,14 +947,45 @@ export_print_page (EvPrintOperationExpor
 	
 	export->total++;
 	export->collated++;
+	
+	// when printing multiple collated copies & multiple pages per sheet we want to 
+	// prevent the next copy starting at the end of the previous one
+	// we therefore check whether we've reached the last page in a document
+	// if that is the case and the given sheet is not filled with pages, we introduce a few blank pages
+	// to finish off the sheet
+	// **export->skipped should not be included in this check!!**
+	if( export->collate == 1 && export->total > 1 && export->pages_per_sheet > 1 && 
+	    (export->page+1) % export->n_pages == 0 && (export->total - 1 + export->skipped) % export->pages_per_sheet != 0 ) {
+		ev_document_doc_mutex_lock ();
+		
+		ev_file_exporter_end_page (EV_FILE_EXPORTER (op->document));
+		
+		ev_file_exporter_begin_page (EV_FILE_EXPORTER (op->document));
+		
+		// export->skipped ensures that new_page and end_page are called in the right places even though
+		// we've skipped a couple of pages on one or more sheets
+		export->skipped += export->pages_per_sheet - (export->total - 1 + export->skipped) % export->pages_per_sheet; // how many pages do we skip when starting a new page?
+		
+		ev_document_doc_mutex_unlock ();
+	}	
+
 
 	if (export->collated == export->collated_copies) {
 		export->collated = 0;
 		if (!export_print_inc_page (export)) {
 			ev_document_doc_mutex_lock ();
-			if (export->pages_per_sheet > 1 &&
-			    export->total - 1 % export->pages_per_sheet == 0)
-				ev_file_exporter_end_page (EV_FILE_EXPORTER (op->document));
+			
+			// commented out because of evince bug http://bugzilla.gnome.org/show_bug.cgi?id=583388
+			// I believe this end_page is extraneous, it causes blank pages to appear at the end
+			// of a document once the bug is fixed
+			/*
+ 			if (export->pages_per_sheet > 1 &&
+			    (export->total - 1 + export->skipped) % export->pages_per_sheet == 0) {
+ 				ev_file_exporter_end_page (EV_FILE_EXPORTER (op->document));
+				
+			} // */
+				
+				
 			ev_file_exporter_end (EV_FILE_EXPORTER (op->document));
 			ev_document_doc_mutex_unlock ();
 
@@ -969,7 +1000,7 @@ export_print_page (EvPrintOperationExpor
 		}
 	}
 
-	if (export->pages_per_sheet == 1 || export->total % export->pages_per_sheet == 1) {
+	if (export->pages_per_sheet == 1 || (export->total + export->skipped) % export->pages_per_sheet == 1 ) {
 		ev_document_doc_mutex_lock ();
 		ev_file_exporter_begin_page (EV_FILE_EXPORTER (op->document));
 		ev_document_doc_mutex_unlock ();
@@ -1317,6 +1348,7 @@ ev_print_operation_export_finalize (GObj
 static void
 ev_print_operation_export_init (EvPrintOperationExport *export)
 {
+	export->skipped = 0;
 }
 
 static GObject *
