-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDF display prototype #78
Comments
From my current research I found out that |
A simple version to show the first page from a PDF on a Gtk window: #include <poppler.h>
#include <gtk/gtk.h>
#include <glib/gprintf.h>
gboolean on_draw_event(GtkWidget *widget, cairo_t *cr) {
GError *e = NULL;
const char *filename = "file:///home/compro/AnnexureE.pdf";
PopplerDocument *doc = poppler_document_new_from_file (filename, NULL, &e);
if (doc == NULL) {
g_fprintf(stderr, "Some error occurred:\n%s", e->message);
exit(1);
}
PopplerPage *doc_page_1 = poppler_document_get_page (doc, 0);
poppler_page_render (doc_page_1, cr);
return FALSE;
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *darea;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
darea = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(window), darea);
g_signal_connect(darea, "draw",
G_CALLBACK(on_draw_event), NULL);
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
gtk_window_set_title(GTK_WINDOW(window), "Draw 1st page from PDF");
gtk_widget_show_all(window);
gtk_main();
return 0;
} To compile and run: gcc `pkg-config --cflags --libs cairo poppler-glib gtk+-3.0` test.c -o test && ./test This is a modified version of the code taken from http://zetcode.com/gui/gtk2/gtkevents/ . |
No step by step guide available
I was looking for Getting Started with Poppler and wasted a lot of time in not looking into the actual documentation itself. The problem is that there is hardly any step by step guide to get started with poppler.
What is poppler?
For people not aware of Poppler; Poppler is basically a very common library I have seen while installing packages in Linux. I hardly had any idea of what it was until I saw that many apps use poppler to display PDFs.
Getting started
a. CPP
b. Glib
c. qt5
poppler-cpp
. So, make sure it(libraries and headers) is installed on your system.g++
for this example.pkg-config
to get that information.g++ `pkg-config --cflags --libs poppler-cpp` x.cpp
./a.out ~/Downloads/pdf/resume.pdf test2.png
While working on this I will be updating about this issue in the comments. If you want you can start a PR since it might take time for me to put up a proper version. I will try my best though.
The text was updated successfully, but these errors were encountered: