//compile with: gcc -Wall `pkg-config cairo poppler-glib --cflags --libs` -g3 leak.c -oleak //check via: valgrind --tool=memcheck --show-possibly-lost=no --leak-check=full ./leak #include #include #include #include #include int main(int argc, char *argv[]) { PopplerDocument *document; PopplerPage *page; double width, height; GError *error; const char *filename; gchar *absolute, *uri; cairo_surface_t *surface; cairo_t *cr; cairo_status_t status; filename = "input.pdf"; g_type_init (); error = NULL; if (g_path_is_absolute(filename)) { absolute = g_strdup (filename); } else { gchar *dir = g_get_current_dir (); absolute = g_build_filename (dir, filename, (gchar *) 0); free (dir); } uri = g_filename_to_uri (absolute, NULL, &error); free (absolute); if (uri == NULL) { printf("poppler fail: %s\n", error->message); return 1; } document = poppler_document_new_from_file (uri, NULL, &error); g_free(uri); if (document == NULL) { printf("poppler fail: %s\n", error->message); return 1; } page = poppler_document_get_page (document, 0); if (page == NULL) { printf("poppler fail: page not found\n"); return 1; } poppler_page_get_size (page, &width, &height); surface = cairo_pdf_surface_create ("/tmp/output.pdf", width, height); cr = cairo_create (surface); cairo_save (cr); poppler_page_render_for_printing (page, cr); cairo_restore (cr); cairo_surface_show_page (surface); status = cairo_status(cr); if (status) printf("%s\n", cairo_status_to_string (status)); cairo_destroy (cr); cairo_surface_finish (surface); status = cairo_surface_status(surface); if (status) printf("surface status error: %s\n", cairo_status_to_string (status)); cairo_surface_destroy (surface); g_object_unref (page); g_object_unref (document); return 0; }