summaryrefslogtreecommitdiff
path: root/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableFooter.java
diff options
context:
space:
mode:
authorAlessandro Iezzi <aiezzi@alessandroiezzi.it>2022-11-11 01:18:06 +0100
committerAlessandro Iezzi <aiezzi@alessandroiezzi.it>2022-11-11 01:18:06 +0100
commit08c017f1304979a1e4c830201a4b45121209ca9c (patch)
treed7fa543e77126f8d27bc03d06d6fa737dfce2a24 /src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableFooter.java
parente736922b5c124ad911c8b17847e4ddc60ce6df9c (diff)
downloadsimply-reports-08c017f1304979a1e4c830201a4b45121209ca9c.tar.gz
simply-reports-08c017f1304979a1e4c830201a4b45121209ca9c.zip
Add classe to generate a document with a single table
Diffstat (limited to 'src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableFooter.java')
-rw-r--r--src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableFooter.java100
1 files changed, 100 insertions, 0 deletions
diff --git a/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableFooter.java b/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableFooter.java
new file mode 100644
index 0000000..f6ce55e
--- /dev/null
+++ b/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableFooter.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2022 Alessandro Iezzi <aiezzi AT alessandroiezzi PERIOD it>
+ *
+ * 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 <https://www.gnu.org/licenses/>.
+ */
+
+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<PdfPCell> {
+ 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);
+ }
+ }
+}