My problem is that I need to add a background to an iText PDF file. The background should fill the whole page and is an image.
Please answer quickly. Thanks for your help
Here is the code and I want to place an image in the background.
Document document = new Document();
PdfPTable table = new PdfPTable(2);
PdfPCell Left = new PdfPCell();
Left.setBorder(0);
Left.setHorizontalAlignment(Element.ALIGN_CENTER);
PdfPCell Right = new PdfPCell();
Right.setBorder(0);
Right.setHorizontalAlignment(Element.ALIGN_CENTER);
try {
PdfWriter.getInstance(document, new
FileOutputStream("C:\\Users\\jensh\\Desktop\\QuizErgebnis.pdf"));
} catch (FileNotFoundException | DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
document.open();
com.itextpdf.text.Font font =
FontFactory.getFont(FontFactory.COURIER, 16, BaseColor.BLACK);
try {
com.itextpdf.text.Image image =
com.itextpdf.text.Image.getInstance("bg.jpg");
} catch (BadElementException | IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
Paragraph H1 = new Paragraph("ZERTIFIKAT", font);
H1.setAlignment(Element.ALIGN_CENTER);
H1.setSpacingAfter(30);
document.add(H1);
table.addCell(Left);
table.addCell(Right);
document.add(table);
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
document.close();