Posted by a ceTe Software moderator
Hello,
Yes, you can add image in background using BackgroundImage page element. You can refer to the documentation on BackgroundImage class
here. Also you can specify the vertical and horizontal alignment for it using AnchorGroup. Below is the code sample for it.
Document document = new Document();
Page page = new Page();
document.getPages().add(page);
String logoImagePath = "Path of image file";
Image image = new Image(logoImagePath, 50, 50);
float width=page.getDimensions().getBody().getWidth();
float height=page.getDimensions().getBody().getHeight();
AnchorGroup anchorGroupObj = new AnchorGroup(width, height,Align.CENTER, VAlign.CENTER);
BackgroundImage backGrundImageObj = new BackgroundImage(logoImagePath);
anchorGroupObj.add(backGrundImageObj);
Template watermarkTemplate = new Template();
watermarkTemplate.getElements().add(anchorGroupObj);
document.setTemplate(watermarkTemplate);
document.draw("C:\\Temp\\MyDocument_Java.pdf");
Thanks,
ceTe Software Support Team.