Search code examples
javapdfprintingappletjbig2

Print PDF that contains JBIG2 images


Please, suggest me some libraries that will help me print PDF files that contain JBIG2 encoded images. PDFRenderer, PDFBox don't help me. These libs can print simple PDF, but not PDF containing JBIG2 images. PDFRenderer tries to fix it (according to bug issue on PDFRedndrer's bug tracker), but some pages still (especially where barcodes exist) don't want to print.

P.S. I use javax.print API within applet

Thanks!

UPDATE: also tried ICEPdf, is too don't want to work.

I came to the conclusion that all these libraries(PDFRenderer, ICEPdf, PDFBox) use JPedals jbig2 decoder. Bug (some pages didn't print) come from this decoder library. The open source version of this decoder (which is used in PDFRenderer, ICEPdf, PDFBox) is no longer supported, but JPedal has a new commercial branch of the project, and they wrote that the bug has been fixed in new commercial release, which costs $9k.

Any ideas?

UPDATE 2: yesterday I tried to replace JPedal's free library with other open-source jbig2-imageio libraries. But yet I don't get any successful results, so I created a new topic on their project's page (google-code's forum - here ). Would be grateful for any help.

I also found some helpfull discussions on Apache PDFBox bug-tracker: here and here.


Solution

  • There is a fork of the JPedal library by Borisvl located at

    https://github.com/Borisvl/JBIG2-Image-Decoder#readme

    which contains speed improvements and I believe it should also fix your bug.

    EDIT : The bug is related to simple range checking. Basically you need to prevent GetPixel from accessing x,y values outside of the bitmap extents.

    You need to make sure the following conditions are met before calling getPixel

    col >= 0 and col < bitmap.width row >= 0 and row < bitmap.height

    Here is some Delphi code with a couple of small range checks. I cannot test the Java code myself but you need to make changes to src/org/jpedal/jbig2/image/JBIG2Bitmap.java

    procedure TJBIG2Bitmap.combine(bitmap: TJBIG2Bitmap; x, y: Integer; combOp: Int64);
    ...
    ...
    var
    begin
      srcWidth := bitmap.width;
      srcHeight := bitmap.height;
      srcRow := 0;
      srcCol := 0;
    
      if (x < 0) then x := 0;
      if (y < 0) then y := 0;
    
      for row := y to Min(y + srcHeight - 1, Self.height - 1) do   // <<<<<<<<  HERE
      begin
        for col := x to x + srcWidth - 1 do
        begin
          srcPixel := bitmap.getPixel(srcCol, srcRow);
    

    Andrew.