Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package org.me.modelos; /** * * @author JR */ import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Phrase; import com.itextpdf.text.Rectangle; import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.PdfPageEventHelper; import com.itextpdf.text.pdf.PdfWriter; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; public class HeaderFooterPageEvent extends PdfPageEventHelper { String motelNombre = "Motel X"; String direccion = "Calle 1, colonia 1 Ciudad Y"; String telefono = "0000000000"; DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); Calendar cal = Calendar.getInstance(); String fecha = dateFormat.format(cal.getTime()); Font font = new Font(Font.FontFamily.HELVETICA, 10, Font.BOLD, new BaseColor(46, 116, 118)); @Override public void onStartPage(PdfWriter writer, Document document) { Rectangle rect = writer.getBoxSize("art"); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(motelNombre + " " + direccion + " " + telefono, font), rect.getLeft(), rect.getTop(), 0); ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER, new Phrase(fecha, font), rect.getRight(), rect.getTop(), 0); } }