user4836562
user4836562

Reputation:

Cannot change itext image border in java

I tried to change the color of itext image border in my java application

Below is the code where i am adding the image to pdf.

Image image = Image.getInstance(new URL(imageUrl));

image.setAbsolutePosition(48f, 723f);
image.scaleAbsolute(65f, 65f);
image.setBorder(Rectangle.BOX); 
image.setBorderWidth(1);
image.setBorderColor(red);

This code is not working. I found that setBorderColor is used for it. But it doesn't work. Any help would be appreciated.

Upvotes: 1

Views: 1676

Answers (3)

Rafi
Rafi

Reputation: 1046

For .Net, Try this Example

Image img = Image.GetInstance("..\\..\\test.jpg");
img.ScalePercent(100.0f*72.0f/img.PlainWidth);

img.Border = Rectangle.BOX; 
img.BorderWidth = 3.0f; 
img.BorderColor = Color.RED;

Upvotes: 0

Samuel Huylebroeck
Samuel Huylebroeck

Reputation: 1719

On iText version 5.5.11 (the development snapshot), this does the trick:

//image == string containing path to my .png image file
Image img = Image.getInstance(image);
img.scaleAbsolute(200,200);
img.setBorder(Rectangle.BOX);
img.setBorderColor(BaseColor.RED);
img.setBorderWidth(1f);

doc.add(img);

A thin, red border is drawn around my image. Modifying width and color changes width and color, as expected.

Which version of iText are you using?

Upvotes: 1

Karthik CP
Karthik CP

Reputation: 1200

Try using

 image.setBorderColor(new Color(231,219,80,255)); 

Upvotes: 0

Related Questions