Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2012 18:24
Show Gist options
  • Save anonymous/3624542 to your computer and use it in GitHub Desktop.
Save anonymous/3624542 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <string.h>
#include <poppler.h>
#define FNAME "file:///path/to/file.pdf"
void
func(PopplerTextAttributes *attr, char *text)
{
static int i = 0;
printf("%d: %s %g (%d-%d)\n", i++, attr->font_name, attr->font_size, attr->start_index, attr->end_index);
printf("%s\n\n", g_utf8_substring(text, attr->start_index, attr->end_index));
}
int
main (int argc, char** argv)
{
PopplerDocument *doc;
PopplerPage *page;
GList *attrs;
GError *err;
gchar *text;
g_type_init();
doc = poppler_document_new_from_file (FNAME, NULL, &err);
page = poppler_document_get_page (doc, 0);
text = poppler_page_get_text (page);
attrs = poppler_page_get_text_attributes(page);
g_list_foreach (attrs, (GFunc) func, text);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment