먼저 윈도우 폴더 Fonts에서 적당한 ttf 파일을 소스폴더/font폴더에 복사한다.(아니면 적당한 다른 폴더에 복사한다. 이때 이클립스는 Navigator View를 사용한다.)
<%@page import="com.itextpdf.text.Font"%>
<%@page import="com.itextpdf.text.pdf.BaseFont"%>
<%@page import="java.io.FileOutputStream"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="com.itextpdf.text.Document" %>
<%@ page import="com.itextpdf.text.DocumentException" %>
<%@ page import="com.itextpdf.text.Paragraph" %>
<%@ page import="com.itextpdf.text.pdf.PdfWriter" %>
<%
Document document = new Document(); //다큐먼트 오브젝트 생성
// step 2
PdfWriter.getInstance(document, new FileOutputStream(getServletContext().getRealPath("/pdf")+"\\" +
"hello.pdf"));
// step 3
document.open();
BaseFont objBaseFont = BaseFont.createFont("font/MALGUN.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//BaseFont.IDENTITY_H //The Unicode encoding with horizontal writing.
Font objFont = new Font(objBaseFont, 12);
//step 4
document.add(new Paragraph("안녕하세요!", objFont));
// step 5
document.close();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<meta http-equiv="Expires" content="0">
<title>Insert title here</title>
</head>
<body>
<!-- <embed src="pdf/hello.pdf" type="application/pdf" width="500" height="375"> -->
<iframe src="pdf/hello.pdf" style="width:100%; height:600px;" frameborder="0">
</iframe>
<!-- <object data="pdf/hello.pdf" type="application/pdf" width="100%" height="100%"> -->
<!-- <p>Adobe Reader를 다운받으시든지, 여기 링크를 클릭하십시오</p> -->
<!-- </object> -->
</body>
</html>
'JSP' 카테고리의 다른 글
| iText table (0) | 2012.07.30 |
|---|---|
| itext 여러개 폰트, 문단 사용 예제 (0) | 2012.07.30 |
| iText hello world (0) | 2012.07.29 |
| 구글맵#3-지오로케이션 (0) | 2012.06.13 |
| 구글맵#2-infoWindow (0) | 2012.06.13 |