]> git.ipfire.org Git - thirdparty/HylaFAX.git/commitdiff
[Bug 319] page-count for PDFs
authorDarren Nickerson <darren.nickerson@ifax.com>
Fri, 2 Aug 2002 17:49:25 +0000 (17:49 +0000)
committerDarren Nickerson <darren.nickerson@ifax.com>
Fri, 2 Aug 2002 17:49:25 +0000 (17:49 +0000)
Thanks to Patrice's fine work, page counts are now no longer zero.

util/SendFaxClient.c++

index 72422c5717a5f0d6a0900b38f64c23e0eae62941..6946c6d8f0b456958291c9c75e41050b4f480a0a 100644 (file)
@@ -775,6 +775,30 @@ SendFaxClient::estimatePostScriptPages(const char* filename)
                    totalPages += npages;
                else if (npagecom > 0)
                    totalPages += npagecom;
+           } else if (memcmp(line, "%PDF", 4) == 0) {
+               int npages = 0;         // # pages according to "/Type /Page"
+               const int slen = 12;    // len of "/Type /Page" + 1 char to check for 's'
+               char* endbuf = line+sizeof(line);
+         
+               rewind(fd);
+               char *cp = line;
+               int len;
+               while ((len = fread(cp, 1, endbuf-cp, fd)) > 0) {
+                    endbuf = cp+len;    // Will only change on the last pass.
+                   cp = line;
+                   while ((cp = (char *) memchr(cp, '/', endbuf-cp-slen))) {
+                       if ((memcmp(cp, "/Type /Page", slen-1) == 0) && (*(cp+slen-1) != 's'))
+                           npages++;
+                       cp++;
+                   }
+                   if ((cp = (char *) memchr(endbuf-slen, '/', slen))) {
+                       memcpy(line, cp, endbuf-cp);
+                       cp = line+(endbuf-cp);
+                   } else
+                       cp = line;
+               }
+               if (npages > 0)
+                   totalPages += npages;
            }
        }
        fclose(fd);