/* * Copyright (C) 2022 Alessandro Iezzi * * This file is part of Simply Reports. * * Simply Reports is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Simply Reports is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with Simply Reports. If not, see . */ package it.alessandroiezzi.simplyreports.pdf; import com.lowagie.text.*; import com.lowagie.text.Font; import com.lowagie.text.Image; import com.lowagie.text.pdf.*; import java.awt.*; import java.io.IOException; import lombok.*; public class PDFTableFooter extends PDFEntity { private PdfReader reader; private @Getter @Setter Integer colspan; private @Getter @Setter Integer height; private @Getter @Setter Integer border; private @Getter @Setter String title; public PDFTableFooter(String logoLocation) { this(logoLocation, null, null, null, null); } public PDFTableFooter(String logoLocation, String title, Integer colspan, Integer height, Integer border) { if (logoLocation != null) { try { this.reader = new PdfReader(logoLocation); } catch (IOException e) { throw new RuntimeException(e); } } this.colspan = colspan; this.height = height; this.border = border; this.title = title; } @Override protected PdfPCell generate(PdfWriter writer) { try { PdfPCell headerCell = new PdfPCell(); headerCell.setPadding(5f); if (reader != null) { PdfImportedPage header = writer.getImportedPage(reader, 1); /* PdfPCell cell = new PdfPCell(Image.getInstance(header)); */ Image headerImage = Image.getInstance(header); headerImage.setWidthPercentage(20f); headerCell.addElement(headerImage); } if (height != null) { headerCell.setFixedHeight(height); } if (border != null) { headerCell.setBorder(border); } if (colspan != null) { headerCell.setColspan(colspan); } if (title != null) { Font f = new Font(Font.HELVETICA, 8.0f, Font.ITALIC, Color.BLACK); // you created a font, but you never used it: Chunk c = new Chunk(title, f); /* c.setBackground(Color.RED); */ // you changed the alignment AFTER adding p1 to the document Paragraph p = new Paragraph(c); p.setAlignment(Element.ALIGN_CENTER); headerCell.addElement(p); } return headerCell; } catch (BadElementException ex) { throw new RuntimeException(ex); } } }