首页 技术 正文

PDF

技术 2022年11月14日
0 收藏 932 点赞 4,675 浏览 2068 个字

源代码请从这里下载:

http://download.csdn.net/source/2984395

使用的是JSP编程

‍ 这是导出后的效果

这是数据库中的内容

‍ 部分代码:

<%@ page language=”java” contentType=”text/html” pageEncoding=”GBK”%>

<%@ page import=”com.jwy.dao.*” %>

<%@ page import=”com.lowagie.text.pdf.*” %>

<%@ page import=”com.lowagie.text.*” %>

<%@ page import=”java.io.*” %>

<html>

<head>

<title>’index.jsp'</title>

<!–

<link rel=”stylesheet” type=”text/css” href=”styles.css”>

–>

</head>

<body>

<%

out.clear();

out = pageContext.pushBody();

response.setHeader(“Content-Disposition”,”attachment;filename=stuInfo.pdf”);

response.setContentType(“application/x-download; charset=utf-8”);

java.util.List<String[]> list = new StuInfoDao().findByAll();

//创建一个对中文字符集支持的基础字体

BaseFont bfChinese = BaseFont.createFont(“STSong-Light”,

“UniGB-UCS2-H”, BaseFont.NOT_EMBEDDED);

//使用基础字体对象创建新字体对像,粗体12号红色字

Font font = new Font(bfChinese, 12, Font.BOLD);

Document document = new Document(PageSize.A4);//创建document对象

PdfWriter.getInstance(document, response.getOutputStream());//创建书写器

document.open();//打开文档

String title = “学生信息表”; //文档标题

Paragraph paragraph = new Paragraph(title, font); //创建段落,并设置字体

paragraph.setAlignment(Paragraph.ALIGN_CENTER);//设置段落居中

document.add(paragraph);//将段落添加到文档中

PdfPTable table = new PdfPTable(5);//建立一个5列的空白表格对象

table.setSpacingBefore(30f);//设置表格上面空白宽度

String[] tableTitle = { “学号”, “姓名”, “性别”, “出生日期”, “联系电话” };//表头

for (int i = 0; i < tableTitle.length; i++) {//循环写入表头

paragraph = new Paragraph(tableTitle[i], new Font(bfChinese, 10,Font.BOLD));

PdfPCell cell = new PdfPCell(paragraph);//建立一个单元格

cell.setHorizontalAlignment(Element.ALIGN_CENTER);//设置内容水平居中显示

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);//设置垂直居中

table.addCell(cell);//将单元格加入表格

}

for(int i=0;i<list.size();i++){//循环写入表文

String[] stuInfo = list.get(i);

for(int j=1;j<stuInfo.length;j++){

PdfPCell cell = new PdfPCell(new Paragraph(stuInfo[j],

new Font(bfChinese, 10)));//建立一个单元格

cell.setHorizontalAlignment(Element.ALIGN_CENTER);//设置内容水平居中显示

cell.setVerticalAlignment(Element.ALIGN_MIDDLE);//设置垂直居中

table.addCell(cell);//将单元格加入表格

}

}

document.add(table);//将表格加入文档中

document.close();//关闭文档

%>

</body>

</html>

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,498
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,137
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,301