summaryrefslogtreecommitdiff
path: root/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableHeader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableHeader.java')
-rw-r--r--src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableHeader.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableHeader.java b/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableHeader.java
new file mode 100644
index 0000000..0df5515
--- /dev/null
+++ b/src/main/java/it/alessandroiezzi/simplyreports/pdf/PDFTableHeader.java
@@ -0,0 +1,94 @@
+/*
+ * 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.BadElementException;
+import com.lowagie.text.Element;
+import com.lowagie.text.Image;
+import com.lowagie.text.Paragraph;
+import com.lowagie.text.pdf.PdfImportedPage;
+import com.lowagie.text.pdf.PdfPCell;
+import com.lowagie.text.pdf.PdfReader;
+import com.lowagie.text.pdf.PdfWriter;
+import java.io.IOException;
+
+import lombok.*;
+
+public class PDFTableHeader 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 PDFTableHeader(String logoLocation) {
+ this(logoLocation, null, null, null, null);
+ }
+
+ public PDFTableHeader(String logoLocation, String title, Integer colspan, Integer height, Integer border) {
+ 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) {
+ Paragraph p = new Paragraph(title);
+ p.setAlignment(Element.ALIGN_CENTER);
+ headerCell.addElement(p);
+ }
+
+ return headerCell;
+ } catch (BadElementException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+}