Skip to content

Commit 3ce2c4b

Browse files
author
Eugene Bochilo
committed
Add setter for background-image and List of background-images
DEVSIX-1948
1 parent 5d6db1e commit 3ce2c4b

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

layout/src/main/java/com/itextpdf/layout/ElementPropertyContainer.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ This file is part of the iText (R) project.
5151
import com.itextpdf.layout.hyphenation.HyphenationConfig;
5252
import com.itextpdf.layout.layout.LayoutPosition;
5353
import com.itextpdf.layout.property.Background;
54+
import com.itextpdf.layout.property.BackgroundImage;
5455
import com.itextpdf.layout.property.BaseDirection;
5556
import com.itextpdf.layout.property.BorderRadius;
5657
import com.itextpdf.layout.property.FontKerning;
@@ -440,6 +441,28 @@ public T setBackgroundColor(Color backgroundColor, float opacity, float extraLef
440441
return (T) (Object) this;
441442
}
442443

444+
/**
445+
* Specifies a background image for the Element.
446+
*
447+
* @param image {@link BackgroundImage}
448+
* @return this Element.
449+
*/
450+
public T setBackgroundImage(BackgroundImage image) {
451+
setProperty(Property.BACKGROUND_IMAGE, image);
452+
return (T) (Object) this;
453+
}
454+
455+
/**
456+
* Specifies a list of background images for the Element.
457+
*
458+
* @param imagesList List of {@link BackgroundImage}
459+
* @return this Element.
460+
*/
461+
public T setBackgroundImage(List<BackgroundImage> imagesList) {
462+
setProperty(Property.BACKGROUND_IMAGE, imagesList);
463+
return (T) (Object) this;
464+
}
465+
443466
/**
444467
* Sets a border for all four edges of this Element with customizable color, width, pattern type.
445468
*

layout/src/test/java/com/itextpdf/layout/BackgroundImageTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ This file is part of the iText (R) project.
5151
import com.itextpdf.kernel.colors.gradients.StrategyBasedLinearGradientBuilder;
5252
import com.itextpdf.kernel.colors.gradients.StrategyBasedLinearGradientBuilder.GradientStrategy;
5353
import com.itextpdf.kernel.geom.Rectangle;
54+
import com.itextpdf.kernel.pdf.PdfArray;
5455
import com.itextpdf.kernel.pdf.PdfDocument;
56+
import com.itextpdf.kernel.pdf.PdfName;
57+
import com.itextpdf.kernel.pdf.PdfString;
5558
import com.itextpdf.kernel.pdf.PdfWriter;
5659
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
5760
import com.itextpdf.kernel.pdf.xobject.PdfFormXObject;
5861
import com.itextpdf.kernel.pdf.xobject.PdfImageXObject;
62+
import com.itextpdf.kernel.pdf.xobject.PdfTransparencyGroup;
5963
import com.itextpdf.kernel.utils.CompareTool;
6064
import com.itextpdf.layout.element.Div;
6165
import com.itextpdf.layout.element.Paragraph;
@@ -191,7 +195,7 @@ public void backgroundImageForText() throws IOException, InterruptedException {
191195

192196
Text textElement = new Text("Lorem ipsum dolor sit amet, consectetur adipiscing elit, " +
193197
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ");
194-
textElement.setProperty(Property.BACKGROUND_IMAGE, backgroundImage);
198+
textElement.setBackgroundImage(backgroundImage);
195199
textElement.setFontSize(50);
196200

197201
doc.add(new Paragraph(textElement));
@@ -537,7 +541,7 @@ private void backgroundXObjectGenericTest(String filename, BackgroundImage backg
537541

538542

539543
Div div = new Div().add(new Paragraph(text + text + text));
540-
div.setProperty(Property.BACKGROUND_IMAGE, backgroundImage);
544+
div.setBackgroundImage(backgroundImage);
541545
doc.add(div);
542546

543547
pdfDocument.close();

0 commit comments

Comments
 (0)