001.
<%--
002.
Document : Create_PDF
003.
Created on : Nov
9
,
2016
,
12
:
03
:
13
PM
004.
Author : Life
005.
--%>
006.
007.
<%
@page
import
=
"com.itextpdf.text.BaseColor"
%>
008.
<%
@page
import
=
"com.itextpdf.text.pdf.BaseFont"
%>
009.
010.
<%
@page
import
=
"com.itextpdf.text.Phrase"
%>
011.
<%
@page
import
=
"com.itextpdf.text.pdf.PdfPCell"
%>
012.
<%
@page
import
=
"com.itextpdf.text.pdf.PdfPTable"
%>
013.
<%
@page
import
=
"com.itextpdf.text.Section"
%>
014.
<%
@page
import
=
"com.itextpdf.text.Chapter"
%>
015.
<%
@page
import
=
"com.itextpdf.text.Paragraph"
%>
016.
<%
@page
import
=
"java.io.FileOutputStream"
%>
017.
<%
@page
import
=
"com.itextpdf.text.pdf.PdfWriter"
%>
018.
<%
@page
import
=
"com.itextpdf.text.Document"
%>
019.
<%
@page
import
=
"com.itextpdf.text.pdf.CMYKColor"
%>
020.
<%
@page
import
=
"com.itextpdf.text.FontFactory"
%>
021.
<%
@page
import
=
"com.itextpdf.text.Font"
%>
022.
023.
<%@ page
import
=
"java.io.File"
%>
024.
<%@ page
import
=
"org.apache.pdfbox.pdmodel.PDDocument"
%>
025.
<%@ page
import
=
"org.apache.pdfbox.pdmodel.PDPage"
%>
026.
<%@ page
import
=
"org.apache.pdfbox.pdmodel.edit.PDPageContentStream"
%>
027.
<%@ page
import
=
"org.apache.pdfbox.pdmodel.font.PDFont"
%>
028.
<%@ page
import
=
"org.apache.pdfbox.pdmodel.font.PDType1Font"
%>
029.
030.
<%@ page
import
=
"java.text.SimpleDateFormat"
%>
031.
<%@ page
import
=
"java.util.Calendar"
%>
032.
<%@ page
import
=
"java.util.Date"
%>
033.
<%@ page
import
=
"java.util.GregorianCalendar"
%>
034.
<%
@page
contentType=
"text/html"
pageEncoding=
"UTF-8"
%>
035.
<% request.setCharacterEncoding(
"UTF-8"
); %>
036.
<!DOCTYPE html>
037.
<html>
038.
<head>
039.
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=UTF-8"
>
040.
<title>JSP Page</title>
041.
</head>
042.
<body>
043.
<%
044.
Calendar c = Calendar.getInstance();
045.
SimpleDateFormat df =
new
SimpleDateFormat(
"dd-MM-yyyy"
);
046.
String currentDate = df.format(c.getTime());
047.
048.
Font blueFont = FontFactory.getFont(
"C:\\Users\\Life\\Downloads\\CS_PraJad-3\\CS_PraJad\\CSPraJad.TTF"
,
8
, Font.NORMAL,
new
CMYKColor(
255
,
0
,
0
,
0
));
049.
Font font = FontFactory.getFont(
"C:\\Users\\Life\\Downloads\\CS_PraJad-3\\CS_PraJad\\CSPraJad.TTF"
,
050.
BaseFont.IDENTITY_H, BaseFont.EMBEDDED,
8
, Font.NORMAL, BaseColor.BLACK);
051.
BaseFont baseFont = font.getBaseFont();
052.
Font redFont = FontFactory.getFont(FontFactory.COURIER,
12
, Font.BOLD,
new
CMYKColor(
0
,
255
,
0
,
0
));
053.
Font yellowFont = FontFactory.getFont(FontFactory.COURIER,
14
, Font.BOLD,
new
CMYKColor(
0
,
0
,
255
,
0
));
054.
Document document =
new
Document();
055.
056.
try
057.
{
058.
PdfWriter writer = PdfWriter.getInstance(document,
new
FileOutputStream(
"C:\\pdf\\StylingExample.pdf"
));
059.
document.open();
060.
061.
PdfPTable my_report_table =
new
PdfPTable(
4
);
062.
PdfPCell table_cell;
063.
064.
String hdept_id =
"กกดกด"
;
065.
066.
table_cell=
new
PdfPCell(
new
Phrase(hdept_id,font));
067.
my_report_table.addCell(table_cell);
068.
String hdept_name=
"กกกกกก"
;
069.
table_cell=
new
PdfPCell(
new
Phrase(hdept_name,font));
070.
my_report_table.addCell(table_cell);
071.
String hmanager_id=
"CCCCCC"
;
072.
table_cell=
new
PdfPCell(
new
Phrase(hmanager_id,font));
073.
my_report_table.addCell(table_cell);
074.
String hlocation_id=
"DDDDDD"
;
075.
table_cell=
new
PdfPCell(
new
Phrase(hlocation_id,font));
076.
my_report_table.addCell(table_cell);
077.
for
(
int
i=
0
;i<
10
;i++) {
078.
String dept_id =
"DEPARTMENT_ID"
;
079.
table_cell=
new
PdfPCell(
new
Phrase(dept_id,blueFont));
080.
my_report_table.addCell(table_cell);
081.
String dept_name=
"DEPARTMENT_NAME"
;
082.
table_cell=
new
PdfPCell(
new
Phrase(dept_name,blueFont));
083.
my_report_table.addCell(table_cell);
084.
String manager_id=
"MANAGER_ID"
;
085.
table_cell=
new
PdfPCell(
new
Phrase(manager_id,blueFont));
086.
my_report_table.addCell(table_cell);
087.
String location_id=
"LOCATION_ID"
;
088.
table_cell=
new
PdfPCell(
new
Phrase(location_id,blueFont));
089.
my_report_table.addCell(table_cell);
090.
}
091.
092.
093.
094.
095.
096.
097.
098.
099.
100.
101.
Paragraph chapterTitle =
new
Paragraph(currentDate, blueFont);
102.
Chapter chapter1 =
new
Chapter(chapterTitle,
1
);
103.
chapter1.setNumberDepth(
0
);
104.
105.
Paragraph sectionContent =
new
Paragraph(
"กกกกกกกกกกกกกกกกกกกกกก"
, blueFont);
106.
chapter1.add(sectionContent);
107.
108.
Paragraph sectionContent2 =
new
Paragraph(
"Section Text content\n\n"
, yellowFont);
109.
sectionContent2.setAlignment(sectionContent2.ALIGN_CENTER);
110.
chapter1.add(sectionContent2);
111.
112.
113.
114.
115.
document.add(chapter1);
116.
117.
118.
document.add(my_report_table);
119.
document.close();
120.
121.
122.
writer.close();
123.
}
catch
(Exception e)
124.
{
125.
e.printStackTrace();
126.
}
127.
%>
128.
129.
</body>
130.
</html>