]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
libcupsfilters: Addded PDF page count function taking the PDF via FILE* pointer
authorTill Kamppeter <till.kamppeter@gmail.com>
Wed, 2 Sep 2020 08:32:00 +0000 (10:32 +0200)
committerTill Kamppeter <till.kamppeter@gmail.com>
Wed, 2 Sep 2020 08:33:04 +0000 (10:33 +0200)
cupsfilters/pdf.cxx
cupsfilters/pdf.h

index 68b1af9121866266d577133124c79b296a028828..12c35d055f47ff221e6fe1a6ea330162064843d0 100644 (file)
@@ -107,6 +107,29 @@ int pdf_pages(const char *filename)
     return -1;
 }
 
+/*
+ * 'pdf_pages_fp()' - Count number of pages in file
+ *                    using QPDF.
+ * I - Pointer to opened PDF file (stdio FILE*)
+ * O - Number of pages or -1 on error
+ */
+int pdf_pages_fp(FILE *file)
+{
+  QPDF *pdf = new QPDF();
+  if (pdf) {
+    try{
+      pdf->processFile("", file, false);
+    } catch(...) {
+      pdf_free(pdf);
+      return -1;
+    }
+    int pages = (pdf->getAllPages()).size();
+    pdf_free(pdf);
+    return pages;
+  } else
+    return -1;
+}
+
 
 /**
  * 'pdf_prepend_stream' - Prepend a stream to the contents of a specified
index eaaf1903fee323686a8b751871ca6d2481f68ff1..ea10b5a4b9fb6c3586d55575eadeaf3210cdbb3c 100644 (file)
@@ -46,6 +46,7 @@ void pdf_resize_page(pdf_t *doc, unsigned page, float width, float length, float
 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);
+int pdf_pages_fp(FILE *file);
 
 #ifdef __cplusplus
 }