package model; import com.itextpdf.text.BaseColor; import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.Element; import com.itextpdf.text.Font; import com.itextpdf.text.Font.FontFamily; import com.itextpdf.text.Phrase; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfPageEventHelper; import com.itextpdf.text.pdf.PdfWriter; import java.io.IOException; public class Watermark extends PdfPageEventHelper { Font font = null; Phrase watermark = null; public Watermark() { font = new Font(createBaseFont(), 70, Font.NORMAL, BaseColor.LIGHT_GRAY); watermark = new Phrase("VÍZJEL ÁRVÍZTŰRŐ", font); } private BaseFont createBaseFont() { BaseFont baseFont = null; try { baseFont = tryCreateBaseFont(); }catch(DocumentException ex) { System.err.println("Hiba a dokumentum készítése közben!"); }catch(IOException ex) { System.err.println("Hiba a dokuementum kiírása közben!"); } return baseFont; } private BaseFont tryCreateBaseFont() throws DocumentException, IOException { BaseFont baseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.EMBEDDED); return baseFont; } @Override public void onEndPage(PdfWriter writer, Document document) { PdfContentByte canvas = writer.getDirectContentUnder(); ColumnText.showTextAligned(canvas, Element.ALIGN_CENTER, watermark, 280, 420, 45); } }