diff options
author | Sebastian J. Bronner <waschtl@sbronner.com> | 2024-02-15 22:27:08 +0000 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2024-02-15 22:27:08 +0000 |
commit | 90726f1e54c3be924f8a0419fc6fca4657127d89 (patch) | |
tree | 6f97004c7b05533a8400e8ff08327daafac5d41c | |
parent | 2934e3127adaff049224c741ddaeef8de832c6ab (diff) |
Enable pdfimages to print filenames to stdout.
Add a command line option -print-filenames so that after writing each
imaage to file, pdfimages will print the filename to stdout. This is in
line with the --batch-print option of scanimage and the stream_filelist
parameter of tesseract. It allows easy parallelization of different
stages of an image processing pipeline.
-rw-r--r-- | utils/ImageOutputDev.cc | 5 | ||||
-rw-r--r-- | utils/ImageOutputDev.h | 4 | ||||
-rw-r--r-- | utils/pdfimages.1 | 3 | ||||
-rw-r--r-- | utils/pdfimages.cc | 3 |
4 files changed, 15 insertions, 0 deletions
diff --git a/utils/ImageOutputDev.cc b/utils/ImageOutputDev.cc index be12f053..74a9a608 100644 --- a/utils/ImageOutputDev.cc +++ b/utils/ImageOutputDev.cc @@ -66,6 +66,7 @@ ImageOutputDev::ImageOutputDev(char *fileRootA, bool pageNamesA, bool listImages dumpJBIG2 = false; dumpCCITT = false; pageNames = pageNamesA; + printFilenames = false; imgNum = 0; pageNum = 0; errorCode = 0; @@ -690,6 +691,10 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str, int w if (inlineImg) { embedStr->restore(); } + + if (printFilenames) { + printf("%s\n", fileName); + } } bool ImageOutputDev::tilingPatternFill(GfxState *state, Gfx *gfx, Catalog *cat, GfxTilingPattern *tPat, const double *mat, int x0, int y0, int x1, int y1, double xStep, double yStep) diff --git a/utils/ImageOutputDev.h b/utils/ImageOutputDev.h index 40bc7713..d23c1638 100644 --- a/utils/ImageOutputDev.h +++ b/utils/ImageOutputDev.h @@ -90,6 +90,9 @@ public: // Use CCITT format for CCITT files void enableCCITT(bool ccitt) { dumpCCITT = ccitt; } + // Print filenames to stdout after writing + void enablePrintFilenames(bool filenames) { printFilenames = filenames; } + // Get the error code // 0 = No error, 1 = Error opening a PDF file, 2 = Error opening an output file, 3 = Error related to PDF permissions, 99 = Other error. int getErrorCode() const { return errorCode; } @@ -150,6 +153,7 @@ private: bool outputPNG; // set to output in PNG format bool outputTiff; // set to output in TIFF format bool pageNames; // set to include page number in file names + bool printFilenames; // set to print image filenames to stdout after writing int pageNum; // current page number int imgNum; // current image number int errorCode; // code for any error creating the output files diff --git a/utils/pdfimages.1 b/utils/pdfimages.1 index 8afa9b79..1a5386a0 100644 --- a/utils/pdfimages.1 +++ b/utils/pdfimages.1 @@ -219,6 +219,9 @@ Specify the user password for the PDF file. .B \-p Include page numbers in output file names. .TP +.B \-print\-filenames +Print image filenames to stdout. +.TP .B \-q Don't print any messages or errors. .TP diff --git a/utils/pdfimages.cc b/utils/pdfimages.cc index 031a4418..937dafc6 100644 --- a/utils/pdfimages.cc +++ b/utils/pdfimages.cc @@ -64,6 +64,7 @@ static bool dumpJBIG2 = false; static bool dumpCCITT = false; static bool allFormats = false; static bool pageNames = false; +static bool printFilenames = false; static char ownerPassword[33] = "\001"; static char userPassword[33] = "\001"; static bool quiet = false; @@ -87,6 +88,7 @@ static const ArgDesc argDesc[] = { { "-f", argInt, &firstPage, 0, "first page to { "-opw", argString, ownerPassword, sizeof(ownerPassword), "owner password (for encrypted files)" }, { "-upw", argString, userPassword, sizeof(userPassword), "user password (for encrypted files)" }, { "-p", argFlag, &pageNames, 0, "include page numbers in output file names" }, + { "-print-filenames", argFlag, &printFilenames, 0, "print image filenames to stdout" }, { "-q", argFlag, &quiet, 0, "don't print any messages or errors" }, { "-v", argFlag, &printVersion, 0, "print copyright and version info" }, { "-h", argFlag, &printHelp, 0, "print usage information" }, @@ -188,6 +190,7 @@ int main(int argc, char *argv[]) imgOut->enableJBig2(dumpJBIG2); imgOut->enableCCITT(dumpCCITT); } + imgOut->enablePrintFilenames(printFilenames); doc->displayPages(imgOut, firstPage, lastPage, 72, 72, 0, true, false, false); } const int exitCode = imgOut->isOk() ? 0 : imgOut->getErrorCode(); |