From ad923f47727349b484729921d30968baec5c9908 Mon Sep 17 00:00:00 2001 From: John Ellson Date: Mon, 1 Jul 2013 00:04:41 -0400 Subject: [PATCH] work in progress --- plugin/poppler/Makefile.test | 10 ++++-- plugin/poppler/gvloadimage_poppler.c | 47 +++++++++++++++++++++++----- plugin/poppler/pdftoimage.c | 3 ++ plugin/poppler/pdftops.c | 1 + 4 files changed, 52 insertions(+), 9 deletions(-) diff --git a/plugin/poppler/Makefile.test b/plugin/poppler/Makefile.test index c652719c7..63734afa1 100644 --- a/plugin/poppler/Makefile.test +++ b/plugin/poppler/Makefile.test @@ -1,11 +1,17 @@ CFLAGS=`pkg-config --cflags cairo poppler-glib` LDFLAGS=`pkg-config --libs cairo poppler-glib` -all: pdftops pdftoimage +all: pdftops pdftoimage hello.png pdftops: pdftops.c pdftoimage: pdftoimage.c +hello.png: pdftoimage hello.pdf + ./pdftoimage hello.pdf hello.png 1 + +hello.pdf: + echo 'digraph {hello->world}' | dot -Tpdf -o hello.pdf + clean: - rm -f pdftops pdftoimage + rm -f pdftops pdftoimage hello.* diff --git a/plugin/poppler/gvloadimage_poppler.c b/plugin/poppler/gvloadimage_poppler.c index 601480fd8..39f56b61b 100644 --- a/plugin/poppler/gvloadimage_poppler.c +++ b/plugin/poppler/gvloadimage_poppler.c @@ -26,14 +26,12 @@ #include "gvplugin_loadimage.h" -// NOT YET +// not ready yet #undef HAVE_POPPLER - #ifdef HAVE_POPPLER #ifdef HAVE_PANGOCAIRO -#include -#include +#include #include #ifdef WIN32 @@ -61,6 +59,7 @@ static void gvloadimage_poppler_free(usershape_t *us) free(poppler); } +#if 0 static int poppler_writer(void *caller_handle, const char *str, int len) { GVJ_t *job = (GVJ_t*)caller_handle; @@ -88,19 +87,53 @@ static void poppler_error(GVJ_t * job, const char *name, const char *funstr, int job->common->errorfn("%s: %s() returned: %d \"%s\" (%s)\n", name, funstr, err, poppler_error_names[-err - 1], errsrc); } +#endif static int gvloadimage_process_file(GVJ_t *job, usershape_t *us, void *instance) { int rc = 0, exit_code; + gchar *absolute, *ura, *dir; + PopplerDocument *document; + PopplerPage *page; + GError *error; + int num_pages; if (! gvusershape_file_access(us)) { job->common->errorfn("Failure to read shape file\n"); return -1; } - rc = popplerapi_run_file(instance, us->name, -1, &exit_code); - if (rc) { - poppler_error(job, us->name, "popplerapi_run_file", rc); + if (g_path_is_absolute(pdf_file)) { + absolute = g_strdup (pdf_file); + } else { + dir = g_get_current_dir (); + absolute = g_build_filename (dir, pdf_file, (gchar *) 0); + free (dir); + } + + uri = g_filename_to_uri (absolute, NULL, &error); + free (absolute); + if (uri == NULL) { + printf("%s\n", error->message); + return 1; } + } + document = poppler_document_new_from_file (uri, NULL, &error); + if (document == NULL) { + printf("%s\n", error->message); + return 1; + } + num_pages = poppler_document_get_n_pages (document); + if (page_num < 1) { + printf("must be at least one page in the pdf\n"); + return 1; + } + + page = poppler_document_get_page (document, 1); + if (page == NULL) { + printf("poppler fail: page 1 not found\n"); + return 1; + } + gvusershape_file_release(us); return rc; } diff --git a/plugin/poppler/pdftoimage.c b/plugin/poppler/pdftoimage.c index a39e24cb4..c0cbdc38e 100644 --- a/plugin/poppler/pdftoimage.c +++ b/plugin/poppler/pdftoimage.c @@ -39,6 +39,9 @@ int main(int argc, char *argv[]) } uri = g_filename_to_uri (absolute, NULL, &error); + + fprintf(stderr, "%s\n%s\n", absolute, uri); + free (absolute); if (uri == NULL) { printf("%s\n", error->message); diff --git a/plugin/poppler/pdftops.c b/plugin/poppler/pdftops.c index 035e0b8d8..610913bc7 100644 --- a/plugin/poppler/pdftops.c +++ b/plugin/poppler/pdftops.c @@ -1,3 +1,4 @@ +#include #include #include #include -- 2.40.0