From c4d79d954978a6b3bf5b6c973fd73dc4e6b460eb Mon Sep 17 00:00:00 2001 From: JaiLuthra1 Date: Mon, 27 Jan 2020 14:18:20 +0530 Subject: [PATCH] pdftopdf- added handling of empty input --- filter/pdftopdf/pdftopdf.cc | 11 +++++++++-- filter/pdftopdf/qpdf_pdftopdf_processor.cc | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/filter/pdftopdf/pdftopdf.cc b/filter/pdftopdf/pdftopdf.cc index e9702a66d..c49fe89d2 100644 --- a/filter/pdftopdf/pdftopdf.cc +++ b/filter/pdftopdf/pdftopdf.cc @@ -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 */ diff --git a/filter/pdftopdf/qpdf_pdftopdf_processor.cc b/filter/pdftopdf/qpdf_pdftopdf_processor.cc index a4baee876..769129f96 100644 --- a/filter/pdftopdf/qpdf_pdftopdf_processor.cc +++ b/filter/pdftopdf/qpdf_pdftopdf_processor.cc @@ -737,7 +737,12 @@ void QPDF_PDFTOPDF_Processor::emitFilename(const char *name) // {{{ out.setExtraHeaderText(extraheader); } out.setPreserveEncryption(false); + std::vector pages=pdf->getAllPages(); + int len=pages.size(); + if (len) out.write(); + else + fprintf(stderr, "DEBUG: Input is empty, outputting empty file.\n"); } // }}} -- 2.47.2