summaryrefslogtreecommitdiffstats
path: root/pdftops-cairo.c
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2011-07-10 21:46:09 +0200
committerFlorian Pritz <bluewind@xinu.at>2011-07-10 21:48:01 +0200
commitd2a44efbe707b7210107fabce58fb99c1a3b251e (patch)
treec5527ba09d85d044326a06393ad8d0f88d8ac167 /pdftops-cairo.c
parent5a311acfe51d396dd65fe72ec478ceebea64f6c1 (diff)
downloadbin-d2a44efbe707b7210107fabce58fb99c1a3b251e.tar.gz
bin-d2a44efbe707b7210107fabce58fb99c1a3b251e.tar.xz
mass commit
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'pdftops-cairo.c')
-rw-r--r--pdftops-cairo.c83
1 files changed, 83 insertions, 0 deletions
diff --git a/pdftops-cairo.c b/pdftops-cairo.c
new file mode 100644
index 0000000..4447d71
--- /dev/null
+++ b/pdftops-cairo.c
@@ -0,0 +1,83 @@
+/* gcc -o pdftops pdftops-cairo.c `pkg-config --cflags --libs cairo poppler-glib` */
+
+#include <poppler.h>
+#include <cairo.h>
+#include <cairo-ps.h>
+
+int main(int argc, char *argv[])
+{
+ PopplerDocument *document;
+ PopplerPage *page;
+ double width, height;
+ GError *error;
+ const char *filename;
+ gchar *absolute, *uri;
+ int num_pages, i;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+ cairo_status_t status;
+
+ if (argc != 2) {
+ printf ("Usage: pdftops-cairo input_file.pdf\n");
+ return 0;
+ }
+
+ filename = argv[1];
+ 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);
+ if (document == NULL) {
+ printf("poppler fail: %s\n", error->message);
+ return 1;
+ }
+
+ num_pages = poppler_document_get_n_pages (document);
+
+ /* Page size does not matter here as the size is changed before
+ * each page */
+ surface = cairo_ps_surface_create ("/dev/stdout", 595, 842);
+ cr = cairo_create (surface);
+ for (i = 0; i < num_pages; i++) {
+ page = poppler_document_get_page (document, i);
+ if (page == NULL) {
+ printf("poppler fail: page not found\n");
+ return 1;
+ }
+ poppler_page_get_size (page, &width, &height);
+ cairo_ps_surface_set_size (surface, width, height);
+ cairo_save (cr);
+ poppler_page_render_for_printing (page, cr);
+ cairo_restore (cr);
+ cairo_surface_show_page (surface);
+ g_object_unref (page);
+ }
+ 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("%s\n", cairo_status_to_string (status));
+ cairo_surface_destroy (surface);
+
+ g_object_unref (document);
+
+ return 0;
+}