A problem with printing files
- From: Jakub Kucharski <dexcret gmail com>
- To: GTK+ App Dev List <gtk-app-devel-list gnome org>
- Subject: A problem with printing files
- Date: Sun, 25 Nov 2012 00:34:47 +0100
I was trying to write a simple application for printing a file. Nothing
important. Just to learn basics. I've written this short piece of code:
#include <gtk/gtk.h>
#include <gtk/gtkunixprint.h>
static void
print_end(GtkPrintJob *print_job, gpointer user_data, const GError *err)
{
if (err == NULL)
return;
g_assert(err == NULL);
}
static void
print_page(GtkWidget *widget, gpointer user_data)
{
GtkWindow *parent = user_data;
GtkPrintJob *print_job;
GtkPrinter *printer;
GtkPrintSettings *settings;
GtkPageSetup *page_setup;
GtkWidget *dialog;
GError *err = NULL;
gboolean status;
dialog = gtk_print_unix_dialog_new(NULL, parent);
if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_APPLY) {
gtk_widget_destroy(dialog);
return;
}
printer = gtk_print_unix_dialog_get_selected_printer(
GTK_PRINT_UNIX_DIALOG(dialog));
settings = gtk_print_unix_dialog_get_settings(
GTK_PRINT_UNIX_DIALOG(dialog));
page_setup = gtk_print_unix_dialog_get_page_setup(
GTK_PRINT_UNIX_DIALOG(dialog));
gtk_widget_destroy(dialog);
print_job = gtk_print_job_new("Example title", printer, settings,
page_setup);
status = gtk_print_job_set_source_file(print_job,
"/home/dexcret/Dokumenty/napisy.pdf", &err);
if (err != NULL) {
g_assert(status != FALSE);
fprintf(stderr, "Unable to print file: %s\n", err->message);
g_error_free(err);
err = NULL;
}
gtk_print_job_send(print_job, print_end, NULL, NULL);
g_object_unref(print_job);
g_object_unref(page_setup);
g_object_unref(settings);
g_object_unref(printer);
}
main(int argc, char **argv)
{
GtkWidget *window;
GtkWidget *button;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_container_set_border_width(GTK_CONTAINER(window), 10);
button = gtk_button_new_with_label("Print");
gtk_container_add(GTK_CONTAINER(window), button);
g_signal_connect(button, "clicked", G_CALLBACK(print_page),
GTK_WINDOW(window));
gtk_widget_show_all(window);
gtk_main();
return 0;
}
But it doesn't work. What have I done wrong?
--
Regards.
Jakub Kucharski
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]