diff -r -U 5 evince-2.20.0.orig/shell/ev-jobs.c evince-2.20.0/shell/ev-jobs.c
--- evince-2.20.0.orig/shell/ev-jobs.c	2007-09-17 18:19:25.000000000 +0200
+++ evince-2.20.0/shell/ev-jobs.c	2007-09-27 16:03:12.000000000 +0200
@@ -228,10 +228,27 @@
 		g_free (job->ranges);
 		job->ranges = NULL;
 		job->n_ranges = 0;
 	}
 
+#ifdef WITH_GTK_PRINT
+	if (job->printer) {
+		g_object_unref(job->printer);
+		job->printer = NULL;
+	}
+	
+	if (job->page_setup) {
+		g_object_unref(job->page_setup);
+		job->page_setup = NULL;
+	}
+	
+	if (job->print_settings) {
+		g_object_unref(job->print_settings);
+		job->print_settings = NULL;
+	}	
+#endif
+
 	(* G_OBJECT_CLASS (ev_job_print_parent_class)->dispose) (object);
 }
 
 static void
 ev_job_print_class_init (EvJobPrintClass *class)
@@ -712,11 +729,18 @@
 		  gint           n_ranges,
 		  EvPrintPageSet page_set,
 		  gint           pages_per_sheet,
 		  gint           copies,
 		  gdouble        collate,
-		  gdouble        reverse)
+		  gdouble        reverse
+#ifdef WITH_GTK_PRINT
+		  ,	
+		  GtkPrinter	    *printer,
+	      	  GtkPrintSettings  *print_settings,
+	      	  GtkPageSetup	    *page_setup
+#endif
+		  )
 {
 	EvJobPrint *job;
 
 	job = g_object_new (EV_TYPE_JOB_PRINT, NULL);
 
@@ -739,10 +763,16 @@
 	
 	job->copies = copies;
 	job->collate = collate;
 	job->reverse = reverse;
 	
+#ifdef WITH_GTK_PRINT
+	job->printer = g_object_ref (printer);
+	job->print_settings = g_object_ref (print_settings);
+	job->page_setup = g_object_ref (page_setup);
+#endif
+	
 	return EV_JOB (job);
 }
 
 static gint
 ev_print_job_get_first_page (EvJobPrint *job)
diff -r -U 5 evince-2.20.0.orig/shell/ev-jobs.h evince-2.20.0/shell/ev-jobs.h
--- evince-2.20.0.orig/shell/ev-jobs.h	2007-09-17 18:19:25.000000000 +0200
+++ evince-2.20.0/shell/ev-jobs.h	2007-09-27 16:03:12.000000000 +0200
@@ -18,11 +18,18 @@
  */
 
 #ifndef __EV_JOBS_H__
 #define __EV_JOBS_H__
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <gtk/gtk.h>
+#ifdef WITH_GTK_PRINT
+#include <gtk/gtkprintunixdialog.h>
+#endif
 #include "ev-document.h"
 #include "ev-window.h"
 #include "ev-selection.h"
 
 G_BEGIN_DECLS
@@ -226,10 +233,15 @@
 	gint pages_per_sheet;
 	gboolean collate;
 	gboolean reverse;
 	gdouble width;
 	gdouble height;
+#ifdef WITH_GTK_PRINT
+    	GtkPrinter	 *printer;
+	GtkPrintSettings *print_settings;
+    	GtkPageSetup	 *page_setup;
+#endif
 };
 
 struct _EvJobPrintClass
 {
 	EvJobClass parent_class;
@@ -298,11 +310,18 @@
 					   gint             n_ranges,
 					   EvPrintPageSet   page_set,
 					   gint             pages_per_sheet,
 					   gint             copies,
 					   gdouble          collate,
-					   gdouble          reverse);
+					   gdouble          reverse
+#ifdef WITH_GTK_PRINT
+					   ,
+					   GtkPrinter		*printer,
+					   GtkPrintSettings *print_settings,
+					   GtkPageSetup		*page_setup
+#endif
+					   );
 void            ev_job_print_run          (EvJobPrint      *print);
 
 G_END_DECLS
 
 #endif /* __EV_JOBS_H__ */
diff -r -U 5 evince-2.20.0.orig/shell/ev-window.c evince-2.20.0/shell/ev-window.c
--- evince-2.20.0.orig/shell/ev-window.c	2007-09-17 18:19:25.000000000 +0200
+++ evince-2.20.0/shell/ev-window.c	2007-09-27 16:03:26.000000000 +0200
@@ -195,14 +195,15 @@
 #endif
 
 #ifdef WITH_GTK_PRINT
 	EvJob            *print_job;
 	gboolean          print_preview;
-	GtkPrintJob      *gtk_print_job;
 	GtkPrinter       *printer;
 	GtkPrintSettings *print_settings;
 	GtkPageSetup     *print_page_setup;
+	guint			  print_job_count;
+	gboolean		  destroy_after_print;
 #endif
 };
 
 #define EV_WINDOW_GET_PRIVATE(object) \
 	(G_TYPE_INSTANCE_GET_PRIVATE ((object), EV_TYPE_WINDOW, EvWindowPrivate))
@@ -2120,37 +2121,16 @@
 		ev_window);
 #endif /* WITH_GTK_PRINT */
 }
 
 #ifdef WITH_GTK_PRINT
-static void
-ev_window_clear_print_job (EvWindow *window)
-{
-	if (window->priv->print_job) {
-		if (!window->priv->print_job->finished)
-			ev_job_queue_remove_job (window->priv->print_job);
-
-		g_signal_handlers_disconnect_by_func (window->priv->print_job,
-						      ev_window_print_job_cb,
-						      window);
-		g_object_unref (window->priv->print_job);
-		window->priv->print_job = NULL;
-	}
-
-	if (window->priv->gtk_print_job) {
-		g_object_unref (window->priv->gtk_print_job);
-		window->priv->gtk_print_job = NULL;
-	}
-}
 
 static void
 ev_window_print_finished (GtkPrintJob *print_job,
 			  EvWindow    *window,
 			  GError      *error)
 {
-	ev_window_clear_print_job (window);
-	
 	if (error) {
 		GtkWidget *dialog;
 		
 		dialog = gtk_message_dialog_new (GTK_WINDOW (window),
 						 GTK_DIALOG_MODAL,
@@ -2165,26 +2145,32 @@
 	} else {
 		/* If printed successfully, save print settings */
 		ev_application_set_print_settings (EV_APP,
 						   window->priv->print_settings);
 	}
+
+ 	window->priv->print_job_count--;
+ 	if (window->priv->destroy_after_print && window->priv->print_job_count == 0) {
+ 		gtk_widget_destroy(GTK_WIDGET(window));	
+ 	}
 }
 
 static void
 ev_window_print_send (EvWindow    *window,
-		      const gchar *filename)
+ 		      const gchar *filename,
+ 		      EvJobPrint *evjob)
 {
 	GtkPrintSettings *settings;
 	EvFileExporterCapabilities capabilities;
 	
 	/* Some printers take into account some print settings,
 	 * and others don't. However we have exported the document
 	 * to a ps or pdf file according to such print settings. So,
 	 * we want to send the exported file to printer with those
 	 * settings set to default values. 
 	 */
-	settings = gtk_print_settings_copy (window->priv->print_settings);
+	settings = g_object_ref(evjob->print_settings);
 	capabilities = ev_file_exporter_get_capabilities (EV_FILE_EXPORTER (window->priv->document));
 
 	gtk_print_settings_set_page_ranges (settings, NULL, 0);
 	gtk_print_settings_set_print_pages (settings, GTK_PRINT_PAGES_ALL);
 	if (capabilities & EV_FILE_EXPORTER_CAN_COPIES)
@@ -2226,25 +2212,25 @@
 		g_free (uri);
 	} else {
 		GtkPrintJob *job;
 		GError      *error = NULL;
 	
-		job = gtk_print_job_new ("evince-print",
-					 window->priv->printer,
-					 settings,
-					 window->priv->print_page_setup);
-
-		if (window->priv->gtk_print_job)
-			g_object_unref (window->priv->gtk_print_job);
-		window->priv->gtk_print_job = job;
+	 	gchar *job_title = (gchar *)gtk_window_get_title(GTK_WINDOW(window));
+	 	if (job_title == NULL) {
+	 		job_title = "evince_print";
+	 	}
+	 	
+	 	job = gtk_print_job_new (job_title,
+	 				 evjob->printer,
+	  				 settings,
+	 				 evjob->page_setup);
 
 		if (gtk_print_job_set_source_file (job, filename, &error)) {
 			gtk_print_job_send (job,
 					    (GtkPrintJobCompleteFunc)ev_window_print_finished,
 					    window, NULL);
 		} else {
-			ev_window_clear_print_job (window);
 			g_warning (error->message);
 			g_error_free (error);
 		}
 	}
 
@@ -2255,17 +2241,16 @@
 ev_window_print_job_cb (EvJobPrint *job,
 			EvWindow   *window)
 {
 	if (job->error) {
 		g_warning (job->error->message);
-		ev_window_clear_print_job (window);
 		return;
 	}
 
 	g_assert (job->temp_file != NULL);
 
-	ev_window_print_send (window, job->temp_file);
+	ev_window_print_send (window, job->temp_file, job);	
 }
 
 static gboolean
 ev_window_print_dialog_response_cb (GtkDialog *dialog,
 				    gint       response,
@@ -2324,12 +2309,10 @@
 		gtk_widget_destroy (msgdialog);
 
 		return FALSE;
 	}
 
-	ev_window_clear_print_job (window);
-	
 	current_page = gtk_print_unix_dialog_get_current_page (GTK_PRINT_UNIX_DIALOG (dialog));
 	print_pages = gtk_print_settings_get_print_pages (window->priv->print_settings);
 	
 	switch (print_pages) {
 	case GTK_PRINT_PAGES_CURRENT:
@@ -2371,24 +2354,36 @@
 	
 	copies = gtk_print_settings_get_n_copies (window->priv->print_settings);
 	collate = gtk_print_settings_get_collate (window->priv->print_settings);
 	reverse = gtk_print_settings_get_reverse (window->priv->print_settings);
 	
-	window->priv->print_job = ev_job_print_new (window->priv->document,
+ 	GtkPrintSettings *job_print_settings = gtk_print_settings_copy(window->priv->print_settings);
+ 	GtkPageSetup *job_page_setup = gtk_page_setup_copy(window->priv->print_page_setup);
+ 	
+ 	EvJob *print_job = ev_job_print_new (window->priv->document,
 						    file_format ? file_format : "ps",
 						    width, height,
 						    ranges, n_ranges,
 						    page_set,
 						    pages_per_sheet,
 						    copies, collate,
-						    reverse);
+						    reverse,
+ 						    window->priv->printer,
+ 						    job_print_settings,
+ 						    job_page_setup);
+
+ 	g_object_unref(job_print_settings);
+ 	g_object_unref(job_page_setup);
 	
-	g_signal_connect (window->priv->print_job, "finished",
+ 	g_signal_connect (print_job, "finished",
 			  G_CALLBACK (ev_window_print_job_cb),
 			  window);
 	/* The priority doesn't matter for this job */
-	ev_job_queue_add_job (window->priv->print_job, EV_JOB_PRIORITY_LOW);
+ 	ev_job_queue_add_job (print_job, EV_JOB_PRIORITY_LOW);
+ 	window->priv->print_job_count++;
+ 	
+ 	g_object_unref(print_job);
 	
 	gtk_widget_destroy (GTK_WIDGET (dialog));
 	window->priv->print_dialog = NULL;
 
 	return TRUE;
@@ -4158,17 +4153,10 @@
 	}
 	
 	ev_window_close_dialogs (window);
 
 #ifdef WITH_GTK_PRINT
-	ev_window_clear_print_job (window);
-
-	if (window->priv->gtk_print_job) {
-		g_object_unref (window->priv->gtk_print_job);
-		window->priv->gtk_print_job = NULL;
-	}
-	
 	if (window->priv->printer) {
 		g_object_unref (window->priv->printer);
 		window->priv->printer = NULL;
 	}
 
@@ -4632,10 +4620,26 @@
 
 	return FALSE;
 }
 
 static gboolean
+window_delete_event_vb (EvWindow *window, GdkEvent *event, gpointer dummy)
+{
+#ifdef WITH_GTK_PRINT
+	if (window->priv->print_job_count > 0) {
+		window->priv->destroy_after_print = TRUE;
+		gtk_widget_hide(GTK_WIDGET(window));
+	} else {
+		gtk_widget_destroy(GTK_WIDGET(window));
+	}
+#else
+	gtk_widget_destroy(GTK_WIDGET(window));
+#endif
+	return TRUE;	
+}
+
+static gboolean
 window_configure_event_cb (EvWindow *window, GdkEventConfigure *event, gpointer dummy)
 {
 	char *uri = window->priv->uri;
 	GdkWindowState state;
 	int x, y, width, height, document_width, document_height;
@@ -5124,10 +5128,15 @@
 	GtkActionGroup *action_group;
 	GtkAccelGroup *accel_group;
 	GError *error = NULL;
 	GtkWidget *sidebar_widget;
 
+	/* catch window delete events to stop window from being deleted
+	 * during printing */
+	g_signal_connect (ev_window, "delete-event",
+			  G_CALLBACK (window_delete_event_vb), NULL);
+	
 	g_signal_connect (ev_window, "configure_event",
 			  G_CALLBACK (window_configure_event_cb), NULL);
 	g_signal_connect (ev_window, "window_state_event",
 			  G_CALLBACK (window_state_event_cb), NULL);
 

