2
* Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2, or (at your option)
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
26
PRINT_DOCUMENT_MARKUPS,
32
GtkWidget *options_combo;
33
PgdPrintOptions options;
36
#define PGD_PRINT_OPTIONS "pgd-print-options"
39
pgd_print_free (PgdPrintDemo *demo)
45
g_object_unref (demo->doc);
53
pgd_print_begin_print (GtkPrintOperation *op,
54
GtkPrintContext *context,
57
gtk_print_operation_set_n_pages (op, poppler_document_get_n_pages (demo->doc));
61
pgd_print_draw_page (GtkPrintOperation *op,
62
GtkPrintContext *context,
68
GtkPrintSettings *settings;
69
PgdPrintOptions options;
70
PopplerPrintFlags flags = 0;
72
page = poppler_document_get_page (demo->doc, page_nr);
76
settings = gtk_print_operation_get_print_settings (op);
77
/* Workaround for gtk+ bug, we need to save the options ourselves */
78
options = demo->options;
80
options = gtk_print_settings_get_int_with_default (settings,
82
PRINT_DOCUMENT_MARKUPS);
86
flags |= POPPLER_PRINT_DOCUMENT;
88
case PRINT_DOCUMENT_MARKUPS:
89
flags |= POPPLER_PRINT_MARKUP_ANNOTS;
91
case PRINT_DOCUMENT_STAMPS:
92
flags |= POPPLER_PRINT_STAMP_ANNOTS_ONLY;
95
g_assert_not_reached ();
98
cr = gtk_print_context_get_cairo_context (context);
99
poppler_page_render_for_printing_with_options (page, cr, flags);
100
g_object_unref (page);
104
pgd_print_create_custom_widget (GtkPrintOperation *op,
108
GtkWidget *label, *combo;
109
GtkPrintSettings *settings;
110
PgdPrintOptions options;
112
settings = gtk_print_operation_get_print_settings (op);
113
options = gtk_print_settings_get_int_with_default (settings,
115
PRINT_DOCUMENT_MARKUPS);
117
hbox = gtk_hbox_new (FALSE, 0);
118
gtk_container_set_border_width (GTK_CONTAINER (hbox), 12);
120
label = gtk_label_new ("Print: ");
121
gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
122
gtk_widget_show (label);
124
combo = gtk_combo_box_new_text ();
125
demo->options_combo = combo;
126
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "Document");
127
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "Document and markup");
128
gtk_combo_box_append_text (GTK_COMBO_BOX (combo), "Document and stamps");
129
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), options);
130
gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0);
131
gtk_widget_show (combo);
133
return G_OBJECT (hbox);
137
pgd_print_custom_widget_apply (GtkPrintOperation *op,
141
GtkPrintSettings *settings;
142
PgdPrintOptions options;
144
settings = gtk_print_operation_get_print_settings (op);
145
options = gtk_combo_box_get_active (GTK_COMBO_BOX (demo->options_combo));
146
/* Workaround for gtk+ bug, we need to save the options ourselves */
147
demo->options = options;
148
gtk_print_settings_set_int (settings, PGD_PRINT_OPTIONS, options);
152
pgd_print_print (GtkWidget *button,
155
GtkPrintOperation *op;
156
GError *error = NULL;
158
op = gtk_print_operation_new ();
159
gtk_print_operation_set_custom_tab_label (op, "PDF Options");
160
g_signal_connect (op, "begin-print",
161
G_CALLBACK (pgd_print_begin_print),
163
g_signal_connect (op, "draw-page",
164
G_CALLBACK (pgd_print_draw_page),
166
g_signal_connect (op, "create_custom_widget",
167
G_CALLBACK (pgd_print_create_custom_widget),
169
g_signal_connect (op, "custom_widget_apply",
170
G_CALLBACK (pgd_print_custom_widget_apply),
172
gtk_print_operation_run (op,
173
GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
174
GTK_WINDOW (gtk_widget_get_toplevel (button)),
179
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (button)),
180
GTK_DIALOG_DESTROY_WITH_PARENT,
183
"%s", error->message);
184
g_error_free (error);
186
g_signal_connect (dialog, "response",
187
G_CALLBACK (gtk_widget_destroy), NULL);
189
gtk_widget_show (dialog);
195
pgd_print_create_widget (PopplerDocument *document)
202
demo = g_new0 (PgdPrintDemo, 1);
204
demo->doc = g_object_ref (document);
206
vbox = gtk_vbox_new (FALSE, 12);
208
hbox = gtk_hbox_new (FALSE, 6);
210
button = gtk_button_new_with_label ("Print...");
211
g_signal_connect (G_OBJECT (button), "clicked",
212
G_CALLBACK (pgd_print_print),
214
gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0);
215
gtk_widget_show (button);
217
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0);
218
gtk_widget_show (hbox);
220
g_object_weak_ref (G_OBJECT (vbox),
221
(GWeakNotify)pgd_print_free,