Commit ce929cf3 authored by Jakob Voss's avatar Jakob Voss Committed by Albert Astals Cid

Add -p flag to pdfimages

Adds the page the image is in to the image filename
parent 6296c289
......@@ -19,6 +19,7 @@
// Copyright (C) 2008 Vasile Gaburici <gaburici@cs.umd.edu>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2009 William Bader <williambader@hotmail.com>
// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -46,11 +47,13 @@
#endif
#include "ImageOutputDev.h"
ImageOutputDev::ImageOutputDev(char *fileRootA, GBool dumpJPEGA) {
ImageOutputDev::ImageOutputDev(char *fileRootA, GBool pageNamesA, GBool dumpJPEGA) {
fileRoot = copyString(fileRootA);
fileName = (char *)gmalloc(strlen(fileRoot) + 20);
fileName = (char *)gmalloc(strlen(fileRoot) + 45);
dumpJPEG = dumpJPEGA;
pageNames = pageNamesA;
imgNum = 0;
pageNum = 0;
ok = gTrue;
}
......@@ -59,6 +62,14 @@ ImageOutputDev::~ImageOutputDev() {
gfree(fileRoot);
}
void ImageOutputDev::setFilename(const char *fileExt) {
if (pageNames) {
sprintf(fileName, "%s-%03d-%03d.%s", fileRoot, pageNum, imgNum, fileExt);
} else {
sprintf(fileName, "%s-%03d.%s", fileRoot, imgNum, fileExt);
}
}
void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
int width, int height, GBool invert,
GBool interpolate, GBool inlineImg) {
......@@ -70,7 +81,7 @@ void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
if (dumpJPEG && str->getKind() == strDCT && !inlineImg) {
// open the image file
sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
setFilename("jpg");
++imgNum;
if (!(f = fopen(fileName, "wb"))) {
error(-1, "Couldn't open image file '%s'", fileName);
......@@ -92,7 +103,7 @@ void ImageOutputDev::drawImageMask(GfxState *state, Object *ref, Stream *str,
} else {
// open the image file and write the PBM header
sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum);
setFilename("pbm");
++imgNum;
if (!(f = fopen(fileName, "wb"))) {
error(-1, "Couldn't open image file '%s'", fileName);
......@@ -137,7 +148,7 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
!inlineImg) {
// open the image file
sprintf(fileName, "%s-%03d.jpg", fileRoot, imgNum);
setFilename("jpg");
++imgNum;
if (!(f = fopen(fileName, "wb"))) {
error(-1, "Couldn't open image file '%s'", fileName);
......@@ -160,7 +171,7 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
colorMap->getBits() == 1) {
// open the image file and write the PBM header
sprintf(fileName, "%s-%03d.pbm", fileRoot, imgNum);
setFilename("pbm");
++imgNum;
if (!(f = fopen(fileName, "wb"))) {
error(-1, "Couldn't open image file '%s'", fileName);
......@@ -191,7 +202,7 @@ void ImageOutputDev::drawImage(GfxState *state, Object *ref, Stream *str,
} else {
// open the image file and write the PPM header
sprintf(fileName, "%s-%03d.ppm", fileRoot, imgNum);
setFilename("ppm");
++imgNum;
if (!(f = fopen(fileName, "wb"))) {
error(-1, "Couldn't open image file '%s'", fileName);
......
......@@ -16,6 +16,7 @@
// Copyright (C) 2006 Rainer Keller <class321@gmx.de>
// Copyright (C) 2008 Timothy Lee <timothy.lee@siriushk.com>
// Copyright (C) 2009 Carlos Garcia Campos <carlosgc@gnome.org>
// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -45,10 +46,11 @@ class ImageOutputDev: public OutputDev {
public:
// Create an OutputDev which will write images to files named
// <fileRoot>-NNN.<type>. Normally, all images are written as PBM
// (.pbm) or PPM (.ppm) files. If <dumpJPEG> is set, JPEG images are
// written as JPEG (.jpg) files.
ImageOutputDev(char *fileRootA, GBool dumpJPEGA);
// <fileRoot>-NNN.<type> or <fileRoot>-PPP-NNN.<type>, if
// <pageNames> is set. Normally, all images are written as PBM
// (.pbm) or PPM (.ppm) files. If <dumpJPEG> is set, JPEG images
// are written as JPEG (.jpg) files.
ImageOutputDev(char *fileRootA, GBool pageNamesA, GBool dumpJPEGA);
// Destructor.
virtual ~ImageOutputDev();
......@@ -63,6 +65,10 @@ public:
// Does this device need non-text content?
virtual GBool needNonText() { return gTrue; }
// Start a page
virtual void startPage(int pageNumA, GfxState *state)
{ pageNum = pageNumA; }
//---- get info about output device
// Does this device use upside-down coordinates?
......@@ -95,10 +101,15 @@ public:
GBool maskInterpolate);
private:
// Sets the output filename with a given file extension
void setFilename(const char *fileExt);
char *fileRoot; // root of output file names
char *fileName; // buffer for output file names
GBool dumpJPEG; // set to dump native JPEG files
GBool pageNames; // set to include page number in file names
int pageNum; // current page number
int imgNum; // current image number
GBool ok; // set up ok?
};
......
......@@ -42,6 +42,9 @@ bypass all security restrictions.
.BI \-upw " password"
Specify the user password for the PDF file.
.TP
.B \-p
Include page numbers in output file names.
.TP
.B \-q
Don't print any messages or errors.
.TP
......
......@@ -17,6 +17,7 @@
//
// Copyright (C) 2007-2008, 2010 Albert Astals Cid <aacid@kde.org>
// Copyright (C) 2010 Hib Eris <hib@hiberis.nl>
// Copyright (C) 2010 Jakob Voss <jakob.voss@gbv.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
......@@ -48,6 +49,7 @@
static int firstPage = 1;
static int lastPage = 0;
static GBool dumpJPEG = gFalse;
static GBool pageNames = gFalse;
static char ownerPassword[33] = "\001";
static char userPassword[33] = "\001";
static GBool quiet = gFalse;
......@@ -65,6 +67,8 @@ static const ArgDesc argDesc[] = {
"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"},
{"-q", argFlag, &quiet, 0,
"don't print any messages or errors"},
{"-v", argFlag, &printVersion, 0,
......@@ -157,7 +161,7 @@ int main(int argc, char *argv[]) {
lastPage = doc->getNumPages();
// write image files
imgOut = new ImageOutputDev(imgRoot, dumpJPEG);
imgOut = new ImageOutputDev(imgRoot, pageNames, dumpJPEG);
if (imgOut->isOk()) {
doc->displayPages(imgOut, firstPage, lastPage, 72, 72, 0,
gTrue, gFalse, gFalse);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment