user1345883
user1345883

Reputation: 451

PDFBox convert PDF to TIFF. Reduce image size in bytes

I'm trying to convert a pdf to a tiff image. I got it working by using pdfbox but the image is too big.

Let's say my PDF size is 224kb => image size=1.4Mb

How can I make the tiff file smaller without losing quality?

Here is some of the code:

TIFFImageWriterSpi tiffspi = new TIFFImageWriterSpi();
writer = tiffspi.createWriterInstance();
ImageWriteParam param = writer.getDefaultWriteParam();
TIFFImageWriteParam param2 = (TIFFImageWriteParam) writer.getDefaultWriteParam();
param2.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);

param2.setCompressionType("LZW");
param2.setCompressionQuality(1.0f);

writer.setOutput(output);
writer.write(null,new IIOImage(image,null,null),param2);

Upvotes: 0

Views: 5248

Answers (1)

Terrible Tadpole
Terrible Tadpole

Reputation: 634

Here are some guidelines:

  • Match the colours to your output. If you are rendering in black and white use bi-value output, which translates to one bit per pixel. If you have few colours without too much shading or mixing like highlight colouring or cartoon-style graphics, use 256 colours. Only use full colour if you have photographs in your PDF. If you have to produce full colour, your quest for smallness is doomed.
  • Match your compression to your colour depth. For monochrome use CCITT T.4 or CCITT T.6, which are way more efficient for bit-sequences. LZW works best on byte-sequences such as 256-colour. If you have to produce full colour, your only hope of decent compression is jpeg, but this will fuzz your text and lines.

Upvotes: 3

Related Questions