FOP image scaling issue in Java
Ok so here's my problem:
We use FOP to create a "pretty" report output. We use the pdf option if the user needs the file, AWT to preview and the -print option to print them. We are using FOP 0.25.x which I fully admit is not the newest version, but upgrading to 0.95 seems like a non-trivial task that I don't necessarily want to undertake.
Anyway, one of our users noticed that when printing ID cards (generated with the FOP -print option) to an ID card printer, the images on the cards (employee photos) had some corruption in them ... sort of like green and red dots and lines. We also found that if we sent the same print request to one of our HP color laser jets, it prints perfectly. To add to the oddity, if we use FOP to create a PDF of the ID card and then print it out with the acrobat reader to the printer, it prints fine.
I eventually found it had something to do with image scaling ... we scaled 600px images to about 120px. If I put the images down, even just half of them, the corruption is noticeably reduced. Likewise, when I enlarged the image, the corruption increased.
So my question is, does anyone know what's going on here? Or ever faced such a problem?
Since I don't know why this is happening, I don't know how to fix the root cause, but I worked with some workarounds:
1) Use FOP to generate PDF image and then print it via Java. This seems like an obvious answer, but some from Google seem to have shown that printing PDFs via Java is not trivial. I've seen the PDF Renderer project on java.net, but it seems pretty cumbersome for one very specific application.
2) Try resizing images before transferring to FOP. This also seemed pretty straightforward to us, however our various users can customize the stylesheets for these IDs, but they want, and the use of "pt" and "in" sizing in them seems to be quite common ... I don't know what a good way to match it is with pixel size.
If anyone has an understanding of the root cause, ways to make this work and / or another idea, you will be in my debt.
a source to share
I ended up doing the second thing I mention in the original question ... i.e. resizing it before passing it to FOP. I found that I can get the dpi on the printer I was printing to and do some math to get the pixel size. Seems to work fine in all my tests ... not a real solution, but an adequate workaround.
a source to share