1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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);
}
}
}
|