DRAX
DRAX

Reputation: 32403

How to remove black border around transparent image in PDF created by iText

I have searched over bunch of sites, and I was unable to find solution for my problem.

This is the problem: I am making PDF's in Java using iText library. Everything works fine except one thing. Transparent PNG images have black/gray border around non-transparent area. I didn't set any borders in code, and actually I have tried to remove them (with no luck).

Can someone help me how to solve this problem?

The closest answer what I have found is: Resizing an image in asp.net without losing the image quality But I cannot (don't know) interpret this code in Java.

My code is pretty big to copy/paste, but these are steps:

  1. create document
  2. load image from given path
  3. manipulate image (resize, rotate, positioning)
  4. add image to current page
  5. save pdf file

This is what I have tried also:

Thanks in advance

UPDATE: I forgot to mention that my original pictures don't have border. Border is created somehow by iText. I initially thought that it was bug, but since iText 5.0.2 this problem remained so now I doubt that is bug (I am currently using 5.1.3).

UPDATE 2 I forgot to add this link: http://itext-general.2136553.n4.nabble.com/template/NamlServlet.jtp?macro=print_post&node=2157261 Here is presented VB script that works, but I cannot convert to Java code (it still draws black border), so can someone help me at least with this to convert good?

Upvotes: 2

Views: 2752

Answers (1)

JCoop
JCoop

Reputation: 11

You could use the java BufferedImage method, getSubImage(x, y, w, h) which allows you to crop a sub image out of an existing image. That way you could cut out the edges.

See here: Class BufferedImage

Upvotes: 0

Related Questions