pdftops_SOURCES = \
filter/common.c \
filter/common.h \
- filter/pdftops.c
+ filter/pdftops.c \
+ filter/pdf.cxx \
+ filter/pdf.h
EXTRA_pdftops_SOURCES = filter/strcasestr.c
-pdftops_CFLAGS = $(CUPS_CFLAGS)
-pdftops_LDADD = $(STRCASESTR) $(CUPS_LIBS)
+pdftops_CFLAGS = \
+ $(CUPS_CFLAGS) \
+ $(LIBQPDF_CFLAGS)
+pdftops_LDADD = \
+ $(STRCASESTR) \
+ $(CUPS_LIBS) \
+ $(LIBQPDF_LIBS)
pdftops_DEPENDENCIES = $(STRCASESTR)
pdftoraster_SOURCES = \
delete pdf;
}
+/*
+ * 'pdf_pages()' - Count number of pages in file
+ * using QPDF.
+ * I - Filename to open
+ * O - Number of pages or -1 on error
+ */
+int pdf_pages(const char *filename)
+{
+ QPDF *pdf = new QPDF();
+ try{
+ pdf->processFile(filename);
+ }catch(...) {
+ return -1;
+ }
+ int pages = (pdf->getAllPages()).size();
+ return pages;
+}
+
/**
* 'pdf_prepend_stream' - Prepend a stream to the contents of a specified
void pdf_resize_page(pdf_t *doc, unsigned page, float width, float length, float *scale);
void pdf_duplicate_page (pdf_t *doc, unsigned page, unsigned count);
int pdf_fill_form(pdf_t *doc, opt_t *opt);
+int pdf_pages(const char *filename);
#ifdef __cplusplus
}
* Include necessary headers...
*/
+#include "pdf.h"
#include <config.h>
#include <cups/cups.h>
#include <cups/ppd.h>
}
+/*
+ * Check whether given file is empty
+ */
+
+int is_empty(char *filename)
+{
+ FILE *fp = NULL;
+ fp = fopen(filename, "rb");
+ if (fp == NULL)
+ {
+ fprintf(stderr, "ERROR: pdftops - cannot open print file \"%s\"\n",
+ filename);
+ exit(1);
+ }
+ else
+ {
+ char buf[1];
+ rewind(fp);
+ if (fread(buf, 1, 1, fp) == 0) {
+ fclose(fp);
+ fprintf(stderr, "DEBUG: Input is empty, outputting empty file.\n");
+ return 1;
+ }
+ fclose(fp);
+ int pages = pdf_pages(filename);
+ if (pages == 0) {
+ fprintf(stderr, "DEBUG: No pages left, outputting empty file.\n");
+ return 1;
+ }
+ if (pages > 0)
+ return 0;
+ exit(1);
+ }
+}
+
+
/*
* Before calling any command line utility, log its command line in CUPS'
* debug mode
tempfile[0] = '\0';
}
+ if (is_empty(filename))
+ return 0;
+
/*
* Read out copy counts and collate setting passed over by pdftopdf
*/