5

I'm trying to convert some .jb2e images, which I extracted from a PDF, into a proper, common image file format like PNG or JPG. I tried using jbig2dec, but that told me

jbig2dec FATAL ERROR Not a JBIG2 file header 

What else can I try?

I'm using Devuan ASCII (~= Debian Stretch).

einpoklum
  • 8,772
  • 19
  • 65
  • 129

2 Answers2

3

I ran into the same issue, and was able to get PNG versions by using pdfimages from the Poppler utils on the original PDF, with the -png flag (and not the -all flag), so that it outputs all the images in the PDF as PNGs.

This is because the -png flag is not the same as the -j and -jbig2 flags (all of these are selected by -all): -png sets the output format, which is the default for all images to be output as, converting if necessary. Converting is actually the default for pdfimages; with no format flags, it converts all images to PBM and PPM files. -j and -jbig2, on the other hand, specify not to convert images of those types, thus they are output in their original format. (Note that this means there's no option to convert images to JPEG in this program; only files stored as JPEGs are output as JPEG with the -j option.)

Dan Getz
  • 1,421
  • 11
  • 17
  • Wouldn't that only work if the PDF was created with PNG rather than JB2E images originally? – einpoklum May 15 '20 at 17:07
  • 1
    No, the `-png` and `-tiff` output options do conversions. The `-j`, `-jp2`, `-jbig2`, and `-ccitt` options request not to convert those file types and to output them as is. The `-all` option outputs some types verbatim, some as TIFF, the rest as PNG. (It was not clear to me either until I read it a lot of times.) – Dan Getz May 15 '20 at 18:09
  • How inconsistent... :-( but thanks. – einpoklum May 15 '20 at 22:05
  • Somehow this silently fails for me. Poppler Utils 0.86.1 on Kubuntu Focal. – jamadagni Mar 15 '21 at 12:30
  • @jamadagni could you share more details of what you tried? Was this a file that output a `.jb2e` when you ran `pdfimages -all`? – Dan Getz Mar 15 '21 at 13:20
  • @DanGetz Hmm thanks for prodding me on this. I tested more and I think the problem is rather that `pdfimages` expects an absolute path for the output, and `.` doesn't cut it. `-png` or `-all` only works when an absolute path is provided. – jamadagni Mar 17 '21 at 08:44
  • @DanGetz Actually the manpage says that I am to (somewhat unexpectedly) provide an “image root”: “writes one file for each image, image-root-nnn.xxx”. This is not an output path but a prefix for the output file paths. So `.` is interpreted as a prefix and I get `.-000.pbm` etc which are of course hidden from `ls` unless I add `-a`. Hence I was thinking it wasn't working. Providing `./` works for selecting current directory and you get `-000.pbm` etc in it. – jamadagni Mar 31 '21 at 05:01
3

If the .jb2e is a single page extracted from a pdf, use:

jbig2dec -t png -o output.png /dev/null input.jb2e

According to jbig2dec's manpage:

jbig2dec [options] global-stream page-stream

If a particular page references no global segment stream, /dev/null can be passed for the global-stream argument to request the embedded parser.

  • Thanks, worked perfectly on my test file. Brings up a question for me: how is one to know that a file is a JBIG2 "segment stream" instead of a "single file"? (Just be aware that both types exist and try each way?) – Dan Getz Jun 09 '20 at 15:17