FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
excel_pdf/JavaTPCProject/src/Project04_A.java at master · TypeP/excel_pdf · GitHub
TypeP
excel_pdf
Repository navigation
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
excel_pdf
/
JavaTPCProject
/
src
/
Project04_A.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
78 lines (62 loc) · 2.21 KB
Breadcrumbs
excel_pdf
/
JavaTPCProject
/
src
/
Project04_A.java
Copy path
File metadata and controls
78 lines (62 loc) · 2.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
java
.
io
.*;
import
com
.
itextpdf
.
text
.*;
import
com
.
itextpdf
.
text
.
pdf
.*;
public
class
Project04_A
{
public
static
void
main
(
String
[]
args
) {
//iText API
String
[]
title
=
new
String
[] {
"제목"
,
"저자"
,
"출판사"
,
"이미지 URL"
};
String
[][]
rows
=
new
String
[][] {
{
"물리법칙의 이해"
,
"리처드 파인먼"
,
"해나무"
,
"https://bookthumb-phinf.pstatic.net/cover/100/365/10036542.jpg"
},
{
"Java의 정석"
,
"남궁성"
,
"도우출판"
,
"https://bookthumb-phinf.pstatic.net/cover/100/365/10036542.jpg"
},
{
"리눅스 프로그램"
,
"창병모"
,
"생능출판"
,
"https://bookthumb-phinf.pstatic.net/cover/100/365/10036542.jpg"
},
};
Document
doc
=
new
Document
(
PageSize
.
A4
);
try
{
PdfWriter
.
getInstance
(
doc
,
new
FileOutputStream
(
new
File
(
"book.pdf"
)));
doc
.
open
();
//한글 폰트
BaseFont
bf
=
BaseFont
.
createFont
(
"H2MJRE.TTF"
,
BaseFont
.
IDENTITY_H
,
BaseFont
.
NOT_EMBEDDED
);
Font
fontTitle
=
new
Font
(
bf
,
12
);
Font
fontRows
=
new
Font
(
bf
,
10
);
PdfPTable
table
=
new
PdfPTable
(
title
.
length
);
table
.
setWidthPercentage
(
100
);
float
[]
colwidth
=
new
float
[]{
20f
,
15f
,
15f
,
30f
};
table
.
setWidths
(
colwidth
);
for
(
String
header
:
title
) {
PdfPCell
cell
=
new
PdfPCell
();
cell
.
setHorizontalAlignment
(
Element
.
ALIGN_CENTER
);
cell
.
setPadding
(
10
);
cell
.
setGrayFill
(
0.9f
);
cell
.
setPhrase
(
new
Phrase
(
header
,
fontTitle
));
table
.
addCell
(
cell
);
}
table
.
completeRow
();
for
(
String
[]
row
:
rows
) {
for
(
String
data
:
row
) {
Phrase
phrase
=
new
Phrase
(
data
,
fontRows
);
PdfPCell
cell
=
new
PdfPCell
(
phrase
);
cell
.
setVerticalAlignment
(
Element
.
ALIGN_MIDDLE
);
cell
.
setPaddingTop
(
20
);
cell
.
setPaddingRight
(
30
);
cell
.
setPaddingBottom
(
20
);
cell
.
setPaddingLeft
(
30
);
table
.
addCell
(
cell
);
}
table
.
completeRow
();
}
PdfPCell
cell4
=
new
PdfPCell
(
new
Phrase
(
"Cell 5"
));
cell4
.
setColspan
(
2
);
PdfPCell
cell5
=
new
PdfPCell
(
new
Phrase
(
"Cell 6"
));
cell5
.
setColspan
(
2
);
table
.
addCell
(
cell4
);
table
.
addCell
(
cell5
);
doc
.
addTitle
(
"PDF Table Demo"
);
doc
.
add
(
table
);
System
.
out
.
println
(
"table 생성 완료"
);
}
catch
(
Exception
e
) {
e
.
printStackTrace
();
}
finally
{
doc
.
close
();
}
}
}
Back
|
FazBrowse Home
|
New Git URL