Images in the header of Itext 5.0

0

I am working with Itext 5.0 for JAVA (use Idea), but I can not find information on how to add images in the header (as if it were a letterhead). The only thing I can do is declare the absolute position of the image with Imagen.setAbsolutePosition() indicating the highest position for the x , y 0 for the y axis, but I see that it still leaves space between the top of the pages and the image (which, being a header does not make much sense). I have the upper and lower margins declared at 0 with documento.setMargins(0, 0, 0, 0); .

My question is how to add the image in the right place.

Very grateful in advance.

    
asked by SergioEsteve 13.07.2017 в 14:52
source

1 answer

0

As you can see below, I define the margins of the document and then I add the image.

This is an example:

Document documento = new Document(PageSize.A4,10,10,10,10);
PdfWriter writer = PdfWriter.getInstance(documento, new FileOutputStream(archivo));
                documento.open();
imagen = Image.getInstance("dirección de la ubicación de tu imagen");
imagen.scalePercent(75f);//esto es opcional para definir el tamaño de la imagen.
imagen.setAlignment(Element.ALIGN_LEFT);
documento.add(imagen);

The result would be:

    
answered by 13.07.2017 в 21:37