Skip to content

Commit c095eb9

Browse files
authored
Merge pull request #18609 from dvohra09/master
Update PDFSampleMain.java to add throws DocumentException to 3 methods - BAEL-9302 Set the Table Cell Width in PDF Using iText in Java
2 parents 895514d + 9ee05f0 commit c095eb9

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

text-processing-libraries-modules/pdf/src/main/java/com/baeldung/pdf/PDFSampleMain.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.nio.file.Paths;
88
import java.util.stream.Stream;
99

10+
import com.itextpdf.text.DocumentException;
1011
import com.itextpdf.text.BadElementException;
1112
import com.itextpdf.text.BaseColor;
1213
import com.itextpdf.text.Document;
@@ -55,19 +56,19 @@ private static void addTableHeader(PdfPTable table) {
5556
});
5657
}
5758

58-
private static void setAbsoluteColumnWidths(PdfPTable table) {
59+
private static void setAbsoluteColumnWidths(PdfPTable table) throws DocumentException {
5960
table.setTotalWidth(500); // Sets total table width to 500 points
6061
table.setLockedWidth(true);
6162
float[] columnWidths = {100f, 200f, 200f}; // Defines three columns with absolute widths
6263
table.setWidths(columnWidths);
6364
}
6465

65-
private static void setAbsoluteColumnWidthsInTableWidth(PdfPTable table) {
66+
private static void setAbsoluteColumnWidthsInTableWidth(PdfPTable table) throws DocumentException {
6667
table.setTotalWidth(new float[] {72f, 144f, 216f}); // First column 1 inch, second 2 inches, third 3 inches
6768
table.setLockedWidth(true);
6869
}
6970

70-
private static void setRelativeColumnWidths(PdfPTable table) {
71+
private static void setRelativeColumnWidths(PdfPTable table) throws DocumentException {
7172
// Set column widths (relative)
7273
table.setWidths(new float[] {1, 2, 1});
7374
table.setWidthPercentage(80); // Table width as 80% of page width

0 commit comments

Comments
 (0)