Commit 08641326 authored by Adrian Johnson's avatar Adrian Johnson

pdfimages: support JBIG2 output

parent 2845ebab
......@@ -56,6 +56,7 @@ public:
virtual int lookChar();
virtual GooString *getPSFilter(int psLevel, const char *indent);
virtual GBool isBinary(GBool last = gTrue);
virtual Object *getGlobalsStream() { return &globalsStream; }
virtual GBool hasGetChars() { return true; }
......@@ -48,6 +48,7 @@
#include "GfxState.h"
#include "Object.h"
#include "Stream.h"
#include "JBIG2Stream.h"
#include "ImageOutputDev.h"
ImageOutputDev::ImageOutputDev(char *fileRootA, GBool pageNamesA, GBool listImagesA) {
......@@ -429,6 +430,30 @@ void ImageOutputDev::writeImage(GfxState *state, Object *ref, Stream *str,
// dump JPEG2000 file
writeRawImage(str, "jp2");
} else if (dumpJBIG2 && str->getKind() == strJBIG2 && !inlineImg) {
// dump JBIG2 globals stream if available
JBIG2Stream *jb2Str = static_cast<JBIG2Stream *>(str);
Object *globals = jb2Str->getGlobalsStream();
if (globals->isStream()) {
FILE *f;
int c;
Stream *str = globals->getStream();
if (!(f = fopen(fileName, "wb"))) {
error(errIO, -1, "Couldn't open image file '{0:s}'", fileName);
while ((c = str->getChar()) != EOF)
fputc(c, f);
// dump JBIG2 embedded file
writeRawImage(str, "jb2e");
} else if (outputPNG) {
// output in PNG format
......@@ -82,6 +82,9 @@ public:
// Use Jpeg2000 format for Jpeg2000 files
void enableJpeg2000(GBool jp2) { dumpJP2 = jp2; }
// Use JBIG2 format for JBIG2 files
void enableJBig2(GBool jbig2) { dumpJBIG2 = jbig2; }
// Check if file was successfully created.
virtual GBool isOk() { return ok; }
......@@ -158,6 +161,7 @@ private:
GBool listImages; // list images instead of dumping
GBool dumpJPEG; // set to dump native JPEG files
GBool dumpJP2; // set to dump native JPEG2000 files
GBool dumpJBIG2; // set to dump native JBIG2 files
GBool outputPNG; // set to output in PNG format
GBool outputTiff; // set to output in TIFF format
GBool pageNames; // set to include page number in file names
......@@ -11,7 +11,7 @@ pdfimages \- Portable Document Format (PDF) image extractor
.B Pdfimages
saves images from a Portable Document Format (PDF) file as Portable
Pixmap (PPM), Portable Bitmap (PBM), Portable Network Graphics (PNG),
Tagged Image File Format (TIFF), JPEG, or JPEG2000 files.
Tagged Image File Format (TIFF), JPEG, JPEG2000, or JBIG2 files.
Pdfimages reads the PDF file
.IR PDF-file ,
......@@ -21,12 +21,12 @@ where
.I nnn
is the image number and
.I xxx
is the image type (.ppm, .pbm, .png, .tif, .jpg, or jp2).
is the image type (.ppm, .pbm, .png, .tif, .jpg, jp2, jb2e, or jb2g).
The default output format is PBM (for monochrome images) or PPM for non-monochrome. The
\-png or \-tiff options change to default output to PNG or TIFF respectively. In addition the \-j and
\-jp2 options will cause JPEG and JPEG2000, respectively, images in the PDF file to be written in their
native format.
\-png or \-tiff options change to default output to PNG or TIFF respectively. In addition the \-j,
\-jp2, and \-jbig2 options will cause JPEG, JPEG2000, and JBIG2, respectively, images in the PDF file
to be written in their native format.
.BI \-f " number"
......@@ -47,6 +47,9 @@ Write images in JPEG format as JPEG files instead of the default format. The JPE
.B \-jp2
Write images in JPEG2000 format as JP2 files instead of the default format. The JP2 file is identical to the JPEG2000 data stored in the PDF.
.B \-jbig2
Write images in JBIG2 format as JBIG2 files instead of the default format. JBIG2 data in PDF is of the embedded type. The embedded type of JBIG2 has an optional separate file containing global data. The embedded data is written with the extension .jb2e and the global data (if available) will be written to the same image number with the extension .jb2g. The content of both these files is indentical to the JBIG2 data in the PDF.
.B \-list
Instead of writing the images, list the images along with various information for each image. Do not specify an
.IR image-root
......@@ -54,6 +54,7 @@ static GBool enablePNG = gFalse;
static GBool enableTiff = gFalse;
static GBool dumpJPEG = gFalse;
static GBool dumpJP2 = gFalse;
static GBool dumpJBIG2 = gFalse;
static GBool pageNames = gFalse;
static char ownerPassword[33] = "\001";
static char userPassword[33] = "\001";
......@@ -78,6 +79,8 @@ static const ArgDesc argDesc[] = {
"write JPEG images as JPEG files"},
{"-jp2", argFlag, &dumpJP2, 0,
"write JPEG2000 images as JP2 files"},
{"-jbig2", argFlag, &dumpJBIG2, 0,
"write JBIG2 images as JBIG2 files"},
{"-list", argFlag, &listImages, 0,
"print list of images instead of saving"},
{"-opw", argString, ownerPassword, sizeof(ownerPassword),
......@@ -187,6 +190,7 @@ int main(int argc, char *argv[]) {
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