To create PDF file we need iText 5 jar. Download iText Jars from iText Website or Maven Repository
SimpleTable.java
Output
Reference : iText Website
Maven Dependency
2.
<
dependency
>
3.
<
groupid
>com.itextpdf</
groupid
>
4.
<
artifactid
>itextpdf</
artifactid
>
5.
<
version
>5.5.11</
version
>
6.
</
dependency
>
SimpleTable.java
01.
package
com.javatutorialcorner.itextpdf;
02.
03.
import
com.itextpdf.text.Document;
04.
import
com.itextpdf.text.DocumentException;
05.
import
com.itextpdf.text.pdf.PdfPTable;
06.
import
com.itextpdf.text.pdf.PdfWriter;
07.
08.
09.
import
java.io.File;
10.
import
java.io.FileOutputStream;
11.
import
java.io.IOException;
12.
13.
public
class
SimpleTable {
14.
public
static
final
String DEST =
"C:/JTC/SimpleTable.pdf"
;
15.
16.
public
static
void
main(String[] args)
throws
IOException,
17.
DocumentException {
18.
File file =
new
File(DEST);
19.
file.getParentFile().mkdirs();
20.
new
SimpleTable().createPdf(DEST);
21.
}
22.
public
void
createPdf(String dest)
throws
IOException, DocumentException {
23.
Document document =
new
Document();
24.
PdfWriter.getInstance(document,
new
FileOutputStream(dest));
25.
document.open();
26.
PdfPTable table =
new
PdfPTable(
8
);
27.
for
(
int
aw =
0
; aw <
16
; aw++){
28.
table.addCell(
"hi"
);
29.
}
30.
document.add(table);
31.
document.close();
32.
}
33.
34.
}
Output
Reference : iText Website
0 comments:
Post a Comment