package com.oraclejava.controller;

import java.util.Date;

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.servlet.ModelAndView;

@Controller

public class HomeController {

@RequestMapping("/home")

public ModelAndView home() {

ModelAndView mav = new ModelAndView("home");

mav.addObject("now", new Date());

return mav;

}

}

package com.oraclejava;

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.web.servlet.view.UrlBasedViewResolver;

import org.springframework.web.servlet.view.tiles3.TilesConfigurer;

import org.springframework.web.servlet.view.tiles3.TilesView;

@Configuration

public class TilesConfig {

@Bean

public UrlBasedViewResolver viewResolver() {

UrlBasedViewResolver tilesResolver = new UrlBasedViewResolver();

tilesResolver.setViewClass(TilesView.class);

return tilesResolver;

}

@Bean

public TilesConfigurer tilesConfigurer() {

TilesConfigurer tiles = new TilesConfigurer();

tiles.setDefinitions("/WEB-INF/tiles.xml");

return tiles;

}

}

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"

"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">

<tiles-definitions>

<definition name="template1-def" template="/WEB-INF/jsp/layout/template1/layout.jsp">

<put-attribute name="title" value="" />

<put-attribute name="header" value="/WEB-INF/jsp/layout/template1/header.jsp" />

<put-attribute name="nav" value="/WEB-INF/jsp/layout/template1/nav.jsp" />

<put-attribute name="content" value="/WEB-INF/jsp/layout/template1/body.jsp" />

<put-attribute name="footer" value="/WEB-INF/jsp/layout/template1/footer.jsp" />

</definition>

<definition name="home" extends="template1-def">

<put-attribute name="title" value="home" />

<put-attribute name="content" value="/WEB-INF/jsp/home/home.jsp" />

</definition>

</tiles-definitions>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title><tiles:getAsString name="title" /> </title>

</head>

<body>

<table width="100%" border="1">

<tr>

<td><tiles:insertAttribute name="header" /> </td>

</tr>

<tr>

<td><tiles:insertAttribute name="nav" /> </td>

</tr>

<tr>

<td><tiles:insertAttribute name="content" /> </td>

</tr>

<tr>

<td><tiles:insertAttribute name="footer" /> </td>

</tr>

</table>

</body>

</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

this is home <br/>

현재 시간은 ${now}

'JSP' 카테고리의 다른 글

페이징(걍 한국식으로 가자...)  (0) 2015.01.16
jw.org의 페이징 원리(대충본것)  (0) 2015.01.16
페이징  (0) 2015.01.16
itext watermark 이미지 넣기  (0) 2012.07.31
iText table db와 연결  (0) 2012.07.30

<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ include file="/WEB-INF/view/header.jsp" %>    

<!DOCTYPE html>

<html lang="ko">

<head>

<meta charset="UTF-8">

<title>자유게시판(리스트)</title>

<style type="text/css">

.mainSection { text-align: center; }

.mainSection table {

margin-left: auto;

margin-right: auto;

}


.pagination { text-align: center; margin: 20px 0; word-spacing: -1em; }

.pagination li { display: inline-block; list-style: none; font: bold 12px/13px Arial, Helvetica, sans-serif; padding: 5px 9px; color: #999; background: #eee; word-spacing: normal; margin: 0 1px; }

.pagination li.first { margin-right: 10px; }

.pagination li.last { margin-left: 10px; }

.pagination li.current { background: #66CC00; color: #fff; }

.pagination li a { display: inline-block; padding: 5px 9px; margin: -5px -9px; text-decoration: none;}

.pagination li a,

.pagination li a:link,

.pagination li a:visited,

.pagination li a:active { background: #666; color: #fff; }

.pagination li a:hover,

.pagination li a:focus { background: #333; }

.pagination li,

.pagination li a {

-moz-border-radius: 5px;

-webkit-border-radius: 5px;

border-radius: 5px;

</style>

<script type="text/javascript">

function goPage(page) {

location.href = '/SpringWeb/boardList.html?pageNum=' + page;

}

</script>

</head>

<body>

<div class="mainSection">

<h2>자유 게시판</h2>

<table border="0" width="600" cellpadding="0" cellspacing="0">

<tr>

<td align="right">

<a href="insert.html">글쓰기</a>

</td>

</tr>

</table>

<table border="1" width="600" cellpadding="0" cellspacing="0">

<tr>

<td width="80">번호</td>

<td width="200">제목</td>

<td width="80">작성자</td>

<td width="80">조회수</td>

<td width="80">파일</td>

<td width="80">날짜</td>

</tr>

<c:forEach var="board" items="${list}">

<tr>

<td width="80">${board.num}</td>

<td width="200">

<a href="detail.html?num=${board.num}">${board.title}</a>

</td>

<td width="80">${board.userid}</td>

<td width="80">${board.count}</td>

<td width="80"><a href="images/${board.filename}">${board.filename}</a></td>

<td width="80"><fmt:formatDate value="${board.regdate}" 

pattern="yyyy/MM/dd HH:mm"/></td>

</tr>

</c:forEach>

</table>

</div>


  

count : ${count} <br/>

totalPage : ${totalPage} <br/>

pageSize : ${pageSize} <br/>

currentPage : ${currentPage} <br/>

prevPage : ${prevPage} <br/>

nextPage : ${nextPage} <br/>

<div class="pagination" style="padding-left:150px;">

             <ul>

             <c:if test="${prevPage gt 0}">

                           <li class="prev"><a href="javascript:goPage(${prevPage});">Prev</a></li>

             </c:if>

                           <c:forEach begin="${1 + prevPage }" end="${nextPage-1}" step="1" varStatus="status">

                                        <c:choose>

                                                     <c:when test="${currentPage eq status.index}">

                                                                  <li 

                                                                  class="current">${status.index}</li>

                                                     </c:when>

                                                     <c:otherwise>

                                                                  <li><a href="javascript:goPage(${status.index});">${status.index}</a></li>

                                                     </c:otherwise>

                                        </c:choose>

                           </c:forEach>

             <c:if test="${totalPage gt nextPage}">

                           <li class="next"><a href="javascript:goPage(${nextPage});">Next</a></li>

             </c:if>

             </ul>

</div>

</body>

</html>









'JSP' 카테고리의 다른 글

tiles  (0) 2019.04.19
jw.org의 페이징 원리(대충본것)  (0) 2015.01.16
페이징  (0) 2015.01.16
itext watermark 이미지 넣기  (0) 2012.07.31
iText table db와 연결  (0) 2012.07.30

5페이지 까지는 그냥 보인다.

5페이지 이상이면 마지막 페이지가 6페이지로 보인다.

예를 들어 총 100페이지이면 1,2,3,4,5,100 이렇게 보인다.

무조건 1페이지와 마지막 페이지는 보인다. 

그래서 만일 현재 페이지가 5페이지이면

1,3,4,5,6,7,100 이렇게 나온다.

7페이지면 

1,5,6,7,8,9,100 이렇게 나온다.

100 페이지이면

1,96,97,98,99,100 이렇게 나온다.

'JSP' 카테고리의 다른 글

tiles  (0) 2019.04.19
페이징(걍 한국식으로 가자...)  (0) 2015.01.16
페이징  (0) 2015.01.16
itext watermark 이미지 넣기  (0) 2012.07.31
iText table db와 연결  (0) 2012.07.30

http://theopentutorials.com/examples/java-ee/jsp/pagination-in-servlet-and-jsp/ 참조


<%@ page language="java" contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ include file="/WEB-INF/view/header.jsp" %>    

<!DOCTYPE html>

<html lang="ko">

<head>

<meta charset="UTF-8">

<title>자유게시판(리스트)</title>

<style type="text/css">

.mainSection { text-align: center; }

.mainSection table {

margin-left: auto;

margin-right: auto;

}


.pagination { text-align: center; margin: 20px 0; word-spacing: -1em; }

.pagination li { display: inline-block; list-style: none; font: bold 12px/13px Arial, Helvetica, sans-serif; padding: 5px 9px; color: #999; background: #eee; word-spacing: normal; margin: 0 1px; }

.pagination li.first { margin-right: 10px; }

.pagination li.last { margin-left: 10px; }

.pagination li.current { background: #66CC00; color: #fff; }

.pagination li a { display: inline-block; padding: 5px 9px; margin: -5px -9px; text-decoration: none;}

.pagination li a,

.pagination li a:link,

.pagination li a:visited,

.pagination li a:active { background: #666; color: #fff; }

.pagination li a:hover,

.pagination li a:focus { background: #333; }

.pagination li,

.pagination li a {

-moz-border-radius: 5px;

-webkit-border-radius: 5px;

border-radius: 5px;

</style>

<script type="text/javascript">

function goPage(page) {

location.href = '/SpringWeb/boardList.html?pageNum=' + page;

}

</script>

</head>

<body>

<div class="mainSection">

<h2>자유 게시판</h2>

<table border="0" width="600" cellpadding="0" cellspacing="0">

<tr>

<td align="right">

<a href="insert.html">글쓰기</a>

</td>

</tr>

</table>

<table border="1" width="600" cellpadding="0" cellspacing="0">

<tr>

<td width="80">번호</td>

<td width="200">제목</td>

<td width="80">작성자</td>

<td width="80">조회수</td>

<td width="80">파일</td>

<td width="80">날짜</td>

</tr>

<c:forEach var="board" items="${list}">

<tr>

<td width="80">${board.num}</td>

<td width="200">

<a href="detail.html?num=${board.num}">${board.title}</a>

</td>

<td width="80">${board.userid}</td>

<td width="80">${board.count}</td>

<td width="80"><a href="images/${board.filename}">${board.filename}</a></td>

<td width="80"><fmt:formatDate value="${board.regdate}" 

pattern="yyyy/MM/dd HH:mm"/></td>

</tr>

</c:forEach>

</table>

</div>

<fmt:formatNumber var="totalPage"  value="${((count - 1) / PAGEBLOCK)}" maxFractionDigits="0" pattern="######"/>

<c:set var="totalPage" value="${totalPage -(totalPage % 1) }" />

<c:set var="totalPage" value="${totalPage + 1 }" />

 

<!--  

count : ${count} <br/>

totalPage : ${totalPage} <br/>

PAGEBLOCK : ${PAGEBLOCK} <br/>

currentPage : ${currentPage} <br/>

-->

<div class="pagination" style="padding-left:150px;">

             <ul>

             <c:if test="${currentPage ne 1}">

                           <li class="prev"><a href="javascript:goPage(${currentPage}-1);">Prev</a></li>

             </c:if>

                           <c:forEach begin="1" end="${totalPage}" step="1" varStatus="status">

                                        <c:choose>

                                                     <c:when test="${currentPage eq status.index}">

                                                                  <li class="current">${status.index}</li>

                                                     </c:when>

                                                     <c:otherwise>

                                                                  <li><a href="javascript:goPage(${status.index});">${status.index}</a></li>

                                                     </c:otherwise>

                                        </c:choose>

                           </c:forEach>

             <c:if test="${currentPage lt totalPage}">

                           <li class="next"><a href="javascript:goPage(${currentPage}+1);">Next</a></li>

             </c:if>

             </ul>

</div>

</body>

</html>









'JSP' 카테고리의 다른 글

페이징(걍 한국식으로 가자...)  (0) 2015.01.16
jw.org의 페이징 원리(대충본것)  (0) 2015.01.16
itext watermark 이미지 넣기  (0) 2012.07.31
iText table db와 연결  (0) 2012.07.30
iText table  (0) 2012.07.30

<%@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.*" %>   
<%@ page import="com.itextpdf.text.pdf.PdfWriter" %>
<%@ page import="com.itextpdf.text.pdf.PdfReader" %>
<%@ page import="com.itextpdf.text.pdf.PdfStamper" %>
<%@ page import="com.itextpdf.text.pdf.PdfContentByte" %>
<%
    Document document = new Document();  //다큐먼트 오브젝트 생성
    // step 2
    PdfWriter.getInstance(document, new FileOutputStream(getServletContext().getRealPath("/pdf")+"\\" +
            "hello.pdf"));
    //watermark
    Image image = Image.getInstance(getServletContext().getRealPath("/images")+"\\"+"watermark.jpg");
    image.setAbsolutePosition(170, 440);
   
   
    // 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();
   
    //stamp찍기
    PdfReader reader = new PdfReader(getServletContext().getRealPath("/pdf")+"\\" + "hello.pdf");
    PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(getServletContext().getRealPath("/pdf")+"\\" + "hello2.pdf"));
    //워터마크 찍기
    PdfContentByte under = stamp.getUnderContent(1);
    under.addImage(image);
    stamp.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/hello2.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' 카테고리의 다른 글

jw.org의 페이징 원리(대충본것)  (0) 2015.01.16
페이징  (0) 2015.01.16
iText table db와 연결  (0) 2012.07.30
iText table  (0) 2012.07.30
itext 여러개 폰트, 문단 사용 예제  (0) 2012.07.30

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="java.util.Iterator, java.util.Hashtable" %>
<%@page import="java.io.FileOutputStream"%>   
<%@ page import="
         org.springframework.web.context.*,
         org.springframework.web.context.support.*"%>   
<%@ page import="com.onj.shopping.business.*" %>   
<%@ page import="com.itextpdf.text.*" %>   
<%@ page import="com.itextpdf.text.Paragraph" %>   
<%@ page import="com.itextpdf.text.pdf.PdfWriter" %>
<%@page import="com.itextpdf.text.pdf.BaseFont"%>
<%@page import="com.itextpdf.text.pdf.PdfPTable"%>
<%@page import="com.itextpdf.text.pdf.PdfPCell"%>
<%@ taglib uri="http://localhost/dclass" prefix="dclass" %> 
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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">
<script type="text/javascript"
 src="<c:url value="/resource/js/jquery-1.7.2.min.js"/>"></script>
<title>D class 쇼핑몰</title>
</head>

<%
ServletContext ctx = pageContext.getServletContext();
WebApplicationContext wac =
  WebApplicationContextUtils.getRequiredWebApplicationContext(ctx);

MemberService ms = (MemberService)wac.getBean("memberService");
Iterator<Product> iter = ms.listProduct().iterator();

Document document = new Document();  //다큐먼트 오브젝트 생성
// step 2
PdfWriter.getInstance(document, new FileOutputStream(getServletContext().getRealPath("/resource/pdf")+"\\" +
  "shop.pdf"));
// step 3
document.open();

BaseFont objBaseFont = BaseFont.createFont("font/H2MJSM.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
//BaseFont.IDENTITY_H  //The Unicode encoding with horizontal writing.
Font objFont = new Font(objBaseFont, 12);
//table
PdfPTable table = new PdfPTable(4);  //4은 열수
PdfPCell cell;
cell = new PdfPCell(new Phrase("품번", objFont));
cell.setBackgroundColor(BaseColor.CYAN);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Phrase("제품명", objFont));
cell.setBackgroundColor(BaseColor.CYAN);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Phrase("가격", objFont));
cell.setBackgroundColor(BaseColor.CYAN);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
cell = new PdfPCell(new Phrase("수량", objFont));
cell.setBackgroundColor(BaseColor.CYAN);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
while (iter.hasNext()) {
 Product p = iter.next();
 table.addCell(p.getProno());
 table.addCell(p.getProname());
 table.addCell(String.valueOf(p.getProprice()));
 table.addCell(String.valueOf(p.getProquantity()));
}
document.add(table);
document.close();
%>   


<body>
<dclass:login>
<iframe src="resource/pdf/shop.pdf" style="width:100%; height:600px;" frameborder="0"></iframe>
</dclass:login>
</body>
</html>

 

 


 

'JSP' 카테고리의 다른 글

페이징  (0) 2015.01.16
itext watermark 이미지 넣기  (0) 2012.07.31
iText table  (0) 2012.07.30
itext 여러개 폰트, 문단 사용 예제  (0) 2012.07.30
iText한글  (0) 2012.07.29

<%@page import="java.io.FileOutputStream"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.itextpdf.text.*" %>   
<%@ page import="com.itextpdf.text.Paragraph" %>   
<%@ page import="com.itextpdf.text.pdf.PdfWriter" %>
<%@page import="com.itextpdf.text.pdf.BaseFont"%>
<%@page import="com.itextpdf.text.pdf.PdfPTable"%>
<%@page import="com.itextpdf.text.pdf.PdfPCell"%>

<%
 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/H2MJSM.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
 //BaseFont.IDENTITY_H  //The Unicode encoding with horizontal writing.
 Font objFont = new Font(objBaseFont, 12);

 //table
 PdfPTable table = new PdfPTable(3);  //3은 열수
 PdfPCell cell;
 cell = new PdfPCell(new Phrase("cell with colspan 3"));
 cell.setColspan(3);
 table.addCell(cell);
 cell = new PdfPCell(new Phrase("Cell with rowspan 2"));
 cell.setRowspan(2);
 table.addCell(cell);
 table.addCell("row 1; cell 1");
 table.addCell("row 1; cell 2");
 table.addCell("row 2; cell 1");
 table.addCell("row 2; cell 2");
 
 
 //step 4
 //document.add(new Paragraph("Hello World 한글!", objFont));
 document.add(table);
 // 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:100%;" frameborder="0">
</iframe>
<!-- <object data="/PdfTest/pdf/hello.pdf" type="application/pdf" width="100%" height="100%"> -->
<!-- <p>Adobe Reader를 다운받으시든지, 여기 링크를 클릭하십시오</p> -->
<!-- </object> -->
</body>
</html>

 

'JSP' 카테고리의 다른 글

itext watermark 이미지 넣기  (0) 2012.07.31
iText table db와 연결  (0) 2012.07.30
itext 여러개 폰트, 문단 사용 예제  (0) 2012.07.30
iText한글  (0) 2012.07.29
iText hello world  (0) 2012.07.29

<%@page import="java.io.FileOutputStream"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%@ page import="com.itextpdf.text.*" %>   
<%@ page import="com.itextpdf.text.pdf.PdfWriter" %>
<%@page import="com.itextpdf.text.pdf.BaseFont"%>

<%
 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/H2MJSM.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
 BaseFont objBaseFont2 = BaseFont.createFont("font/H2GTRE.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
 //BaseFont.IDENTITY_H  //The Unicode encoding with horizontal writing.
 Font objFont = new Font(objBaseFont, 12);
 Font titleFont = new Font(objBaseFont2, 24);
 
 //step 4
 Paragraph para1 = new Paragraph("신청서", titleFont);
 para1.setAlignment(Element.ALIGN_CENTER);
 document.add(para1);
 
 Paragraph para2 = new Paragraph("신청서입니다", objFont);
 para2.setAlignment(Element.ALIGN_LEFT);
 document.add(para2);
 
 // 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:100%;" frameborder="0">
</iframe>
<!-- <object data="/PdfTest/pdf/hello.pdf" type="application/pdf" width="100%" height="100%"> -->
<!-- <p>Adobe Reader를 다운받으시든지, 여기 링크를 클릭하십시오</p> -->
<!-- </object> -->
</body>
</html>

 

'JSP' 카테고리의 다른 글

iText table db와 연결  (0) 2012.07.30
iText table  (0) 2012.07.30
iText한글  (0) 2012.07.29
iText hello world  (0) 2012.07.29
구글맵#3-지오로케이션  (0) 2012.06.13

먼저 윈도우 폴더 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

PDF 출력 iText 라이브러리 설치

http://itextpdf.com/

 

iText download에서 community를 다운로드함

 

압축풀고 itextpdf-5.3.0.pdf를 라이브러리에 등록

 

<%@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();
 //step 4
 document.add(new Paragraph("Hello World!"));
 // 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 여러개 폰트, 문단 사용 예제  (0) 2012.07.30
iText한글  (0) 2012.07.29
구글맵#3-지오로케이션  (0) 2012.06.13
구글맵#2-infoWindow  (0) 2012.06.13
구글맵#1  (0) 2012.06.13

+ Recent posts