Using native unix print system
- From: Martin Fischer <martinfischer8 t-online de>
- To: gtk-app-devel-list gnome org
- Subject: Using native unix print system
- Date: Sun, 18 Oct 2015 11:34:45 +0200
Hi,
I'm trying to use the Unix native print system of GTK+ 2 at the moment.
I'm not able to create any output neither to the printer nor to file.
In order to track down the problem a bit more, I created a small test
application:
----
#include <gtk/gtk.h>
#include <gtk-unix-print-2.0/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;
cairo_t *cr;
cairo_surface_t *surface;
char * status;
dialog = gtk_print_unix_dialog_new(NULL, parent);
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
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));
print_job = gtk_print_job_new("Example title", printer, settings,
page_setup);
surface = gtk_print_job_get_surface( print_job, NULL );
cr = cairo_create( surface );
status = cairo_status_to_string( cairo_status( cr ));
cairo_set_source_rgb(cr, 0.6, 0.6, 0.6);
cairo_set_line_width(cr, 1);
cairo_rectangle(cr, 20, 20, 120, 80);
cairo_rectangle(cr, 180, 20, 80, 80);
cairo_stroke_preserve(cr);
cairo_fill(cr);
cairo_show_page( cr );
status = cairo_status_to_string( cairo_status( cr ));
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);
}
gtk_widget_destroy(dialog);
return;
}
int
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;
}
----
This is the Makefile
----
EXES = unixprint
CC = cc
CFLAGS = -Wall -g -I /usr/include/gtk-unix-print-2.0 `pkg-config
--cflags --libs gtk+-2.0` `pkg-config --cflags --libs gtk+-unix-print-2.0`
all:
$(MAKE) $(EXES)
%: %.c
$(CC) $(CFLAGS) $ c -o $@
clean:
rm -f $(EXES) *.o
----
Everything seems to work, I don't get any error messages and print_end
is called. When printing to file the files are created with a zero byte
length, whether I select PDF or PS.
So I'm pretty much clueless. It looks like I'm missing something basic
but what? Searching the Internet didn't help.
So any hints or ideas?
Regards
Martin
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]