1

• Background :

We are developing AFP to PDF tool. It involves conversion of AFP (Advanced Function Processing) file to PDF.

• Detailed Problem statement :

We have AFP file with embedded TIFF Image. The image object is described in Function Set 45, represented somewhat like this -


Image Content
 Begin Tile
  Image Encoding Parameter – TIFF LZW
   Begin Transparency Mask
      Image Encoding Parameter – G4MMR
      Image Data Elements 
   End Transparency Mask
   Image Data Elements (IDE Size 32) – 4 bands: CMYK
End Tile
End Image Content

We want to write this tiled image to PDF either using Java /iText API. As of now, we can write G4MMR image. But, we are not able to apply CMYK color band data (Blue Color) to this image.

• Solution tried :

The code to write G4MMR image goes as follows –


ByteArrayOutputStream decode = saveAsTIFF(<width>,<height>,<imageByteData>);                                    
RandomAccessFileOrArray ra=new RandomAccessFileOrArray(saveAsTIFF.toByteArray());          
int pages = TiffImage.getNumberOfPages(ra); 
for(int i1 = 1; i1 <= pages; i1++){
img1 = TiffImage.getTiffImage(ra, i1);                     
}
img1.scaleAbsolute(256, 75);      
document.add(img1); 

saveAsTIFF method is given here – http://www.jpedal.org/PDFblog/2011/08/ccitt-encoding-in-pdf-files-converting-pdf-ccitt-data-into-a-tiff/ As mentioned, we are not able to apply CMYK 4 band image color data to this G4MMR image.

• Technology stack with versions of each component :
1. JDK 1.6
2. itextpdf-5.1




-- Umesh Pathak

UmeshPathak
  • 145
  • 1
  • 2
  • 13

2 Answers2

2

The AFP resource you're showing is a TIFF CMYK image compressed with LZW. This image is also using a "transparency mask" which is compressed with G4MMR ( a slightly different encoding than the traditional Fax style G4).

So the image data is already using the CMYK colorspace, each band (C,M,Y,K) is compressed alone using simple LZW encoding and should not be too difficult to extract and store as a basic TIFF CMYK file. You'll also have to convert the transparency mask to G4 or raw data to use it in a pdf file to maks the CMYK image.

If you want better PDF output control, I suggest you take a look at pdflib

user18428
  • 1,216
  • 11
  • 17
  • How to decrypt the image which is LZW encrypted ? – UmeshPathak Sep 20 '12 at 09:02
  • Sorry I said LZW encryption when I meant LZW encoding (I edited the answer). A simple LZW codec should do. Another option is to use libtiff (I don't know if there is a java binding though) which expose the TIFFWriteRawStrip method which allow to store each band without decoding it.If you want to go that way *i can post some pseudocode if you like – user18428 Sep 25 '12 at 07:27
0

You need to add a CMYK colorspace to your image before adding it to the PDF file. However I am afraid this might not be fully supported in iText.
A workaround for you could be to convert your image into the default RGB colorspace before adding it to the PDF file, however this will probably imply some quality loss for your image.

yms
  • 10,361
  • 3
  • 38
  • 68