]> git.ipfire.org Git - thirdparty/cups-filters.git/commitdiff
pdftopdf- added handling of empty input 195/head
authorJaiLuthra1 <luthrajaiji@gmail.com>
Mon, 27 Jan 2020 08:48:20 +0000 (14:18 +0530)
committerJaiLuthra1 <luthrajaiji@gmail.com>
Mon, 27 Jan 2020 08:48:20 +0000 (14:18 +0530)
filter/pdftopdf/pdftopdf.cc
filter/pdftopdf/qpdf_pdftopdf_processor.cc

index e9702a66da1f54efbfe1795f2373b6385ef28845..c49fe89d21e67ed45a734e6ecb48ae8e05dce3df 100644 (file)
@@ -1107,6 +1107,7 @@ int main(int argc,char **argv)
        external utilities pdftocairo or Ghostscript, but these make
        the processing slower, especially due to extra piping of the
        data between processes. */
+    int empty = 0;
     int qpdf_flatten = 1;
     int pdftocairo_flatten = 0;
     int gs_flatten = 0;
@@ -1138,17 +1139,23 @@ int main(int argc,char **argv)
     if (argc==7) {
       if (!proc->loadFilename(argv[6],qpdf_flatten)) {
         ppdClose(ppd);
-        return 1;
+        empty = 1;
       }
     } else {
       tmpfile = copy_stdin_to_temp();
       if ((!tmpfile)||
          (!proc->loadFile(tmpfile,WillStayAlive,qpdf_flatten))) {
         ppdClose(ppd);
-        return 1;
+        empty = 1;
       }
     }
 
+    if(empty)
+    {
+      fprintf(stderr, "DEBUG: Input is empty, outputting empty file.\n");
+      return 0;
+    }
+
     /* If the input file contains a PDF form and we opted for not
        using QPDF for flattening the form, we pipe the PDF through
        pdftocairo or Ghostscript here */
index a4baee8760afc0804d9849b5cc5d78f25b4dc8a4..769129f96f71c6c2d8fd1e9575c832e5bcd884a8 100644 (file)
@@ -737,7 +737,12 @@ void QPDF_PDFTOPDF_Processor::emitFilename(const char *name) // {{{
     out.setExtraHeaderText(extraheader);
   }
   out.setPreserveEncryption(false);
+  std::vector<QPDFObjectHandle> pages=pdf->getAllPages();
+  int len=pages.size();
+  if (len)
   out.write();
+  else
+  fprintf(stderr, "DEBUG: Input is empty, outputting empty file.\n");
 }
 // }}}