I\'m using iText to generate a PDF. I created a custom PdfPageEventHelper to add a header (and footer) to each page.
My problem is I don\'t know how to add the imag
A generic solution to add image at the top of the page. We can do it by positing image to the top also. it may fix your requirement
public static void main(String[] args) throws MalformedURLException, IOException, DocumentException {
Document document = new Document();
try {
PdfWriter.getInstance(document,
new FileOutputStream("HelloWorld.pdf"));
document.open();
//
// Scale the image to a certain percentage
//
String filename = "image.jpg";
Image image = Image.getInstance(filename);
image = Image.getInstance(filename);
image.scalePercent(200f);
image.setAbsolutePosition(0, (float) (PageSize.A4.getHeight() - 20.0));
System.out.println(image.getScaledHeight());
document.add(image);
//
// Scales the image so that it fits a certain width and
// height
//
image.scaleToFit(100f, 200f);
document.add(image);
document.add(new Chunk("This is chunk 3. "));
System.out.println("created");
} catch (DocumentException | IOException e) {
e.printStackTrace();
} finally {
document.close();
}
}
}