[poppler] No more poppler_page_render_to_pixbuf with Ubuntu 12.04
Adrian Johnson
ajohnson at redneon.com
Fri Apr 27 19:06:42 PDT 2012
On 28/04/12 09:30, Craig wrote:
> Hi,
>
> I used the code below to render a page of a pdf to a scrolled window in
> a gtk application of mine.
> After downloading Ubuntu 12.04 I get that there is no more support for
> poppler_page_render_to_pixbuf().
> I do know that we are supposed to use cairo. But how? How do I replace
> the code below with cairo?
You use the poppler_page_render() and poppler_page_render_for_printing()
functions.
Have a look at the poppler glib demo. The glib/demo/render.c file in
http://poppler.freedesktop.org/poppler-0.18.4.tar.gz demonstrates
rendering a pdf using gtk.
The is also a cairo pdf rendering example at
http://www.cairographics.org/renderpdf/
> these are global variables
>
> static PopplerDocument *doc;
> static PopplerPage *page;
> GdkPixbuf *pixbuf;
> GtkWidget *image;
>
> void open_pdf_file_on_lily_complete()
> {
> GtkWidget *viewport, *window, *hpane, *entry;
> GtkScrolledWindow *scrolledwindow;
> GError* err = NULL;
> GString *link;
> gchar *uri;
> window = GTK_WIDGET(gtk_builder_get_object (builder, "window"));
> link = make_ly_extension_into_pdf();
> uri = g_filename_to_uri(link->str, NULL, NULL);
> g_string_free(link, TRUE);
> doc = poppler_document_new_from_file(uri, NULL, &err);
> total_pages = 0;
> width = 0.0;
> height = 0.0;
> if(doc!= NULL)
> {
> scrolledwindow = GTK_SCROLLED_WINDOW(gtk_builder_get_object (builder,
> "pdfscrollview"));
> hpane = GTK_WIDGET(gtk_builder_get_object(builder, "ly_pdf_hpane"));
> total_pages = poppler_document_get_n_pages(doc);
> if(page_num > total_pages) page_num = 0;
> page = poppler_document_get_page(doc, page_num);
> poppler_page_get_size(page, &width, &height);
> pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, width, height);
> poppler_page_render_to_pixbuf(page, 0, 0, width, height, 1, 0, pixbuf);
> image = gtk_image_new_from_pixbuf(pixbuf);
> viewport = gtk_bin_get_child(GTK_BIN(scrolledwindow));
> if(viewport ) gtk_container_remove(GTK_CONTAINER(scrolledwindow), viewport);
> gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW
> (scrolledwindow), image);
> viewport = gtk_bin_get_child(GTK_BIN(scrolledwindow));
> gtk_widget_add_events(viewport, GDK_POINTER_MOTION_MASK |
> GDK_BUTTON_PRESS_MASK);
> g_signal_connect(G_OBJECT(viewport), "motion_notify_event",
> G_CALLBACK(motion_notify), image);
> g_signal_connect(G_OBJECT(viewport), "button-press-event",
> G_CALLBACK(mouse_down), image);
> gtk_paned_set_position(GTK_PANED(hpane), 500);
> window = GTK_WIDGET(gtk_builder_get_object (builder, "window"));
> entry = GTK_WIDGET(gtk_builder_get_object (builder,
> "Entry"));
> gchar *my_string = g_strdup_printf("%i", page_num + 1);
> gtk_entry_set_text(GTK_ENTRY(entry), my_string);
> gtk_widget_show_all (window);
> }
> }
>
>
> _______________________________________________
> poppler mailing list
> poppler at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/poppler
More information about the poppler
mailing list