- 浏览: 3498 次
- 性别:
- 来自: 辽宁
最新评论
下载bcprov-jdk15-139.jar,
iText-2.1.7.jar,
iTextAsian.jar,
iTextAsianCmaps.jar夹包
前台index.jsp如下:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html; charset=utf-8" isELIgnored="false"%>
<%
String path = request.getContextPath();
%>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>欢迎来到pdf打印功能实现网站</title>
<head>
<script type="text/javascript" language="javascript" src="<%=path %>/js/jquery.js"></script>
<script type="text/javascript">
function export_report(){
var tableHeader="";
var tableBody="";
//获取表格信息
$("#tableResult tr").each(function(i,_tr){
$(_tr).children().each(function(k,_td){
if(i==0){
tableHeader+=$.trim($(_td).text())+",";
}else{
tableBody+=$.trim($(_td).text())+"##";
}
});
if(i>0){
tableBody+="@@";
}
});
if(tableHeader==""){
alert("表头未初始化!");
return false;
}
if(tableBody==""){
alert("表格体没内容!");
return false;
}
$("#report_tableHeader").val(tableHeader);
$("#report_tableBody").val(tableBody);
$("#report_form").submit();
}
</script>
</head>
<body>
<form action="#" method="post" target="_self" name="naturalPerson" id="naturalPerson">
<div class="dispaly-div" >
<table id="tableResult" width="100%" border="1" align="center" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" class="sortable">
<thead>
<tr style="cursor: pointer;">
<td height="28" align="center" class="td_LTBG">户人编号</td>
<td height="28" align="center" class="td_LTBG">户编号</td>
<td height="28" align="center" class="td_LTBG">姓名</td>
<td height="28" align="center" class="td_LTBG">性别</td>
<td height="28" align="center" class="td_LTBG">现居住地</td>
<td height="28" align="center" class="td_LTBG">户籍所在地</td>
<td height="28" align="center" class="td_LTBG">身份证号码</td>
<td height="28" align="center" class="td_LTBG">出生日期</td>
<td height="28" align="center" class="td_LTBG">民族</td>
<td height="28" align="center" class="td_LTBG">文化程度</td>
<td height="28" align="center" class="td_LTBG">户口性质</td>
<td height="28" align="center" class="td_LTBG">婚姻状况</td>
</tr>
</thead>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
</table>
</div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" align="right" class="td_RB">
<span style="margin-right: 3%;">
<a id="expor_pdf" onclick="return export_report();" style="cursor: pointer;">打印PDF</a>
</span>
</td>
</tr>
</table>
</form>
<form action="<%=path%>/ExportServletPdf" method="post" id="report_form">
<input type="hidden" name="type" id="report_type"/>
<input type="hidden" name="tableHeader" id="report_tableHeader"/>
<input type="hidden" name="tableBody" id="report_tableBody"/>
</form>
</body>
</html>
后台CommonPdf.java封装类如下:
public class CommonPdf {
private static String CHINA_FONT_SONGTI = "STSongStd-Light"; //宋体
private static String ENCODE_GB = "UniGB-UCS2-H"; // 中文编码GB(横版)
/**
* 取得基本字体
* @param font
* @param encode
* @return
*/
public BaseFont getBaseFont(String font, String encode){
BaseFont bfChinese = null;
try {
bfChinese = BaseFont.createFont(font, encode, false);
} catch (Exception e) {
e.printStackTrace();
}
return bfChinese;
}
/**
*取得具体字体
* @param baseFont 基本字体
* @param fontSize 字体大小 ,如12
* @param fontStyle 字体样式, 如com.lowagie.text.Font.BOLD(粗), Font.ITALIC(斜), Font.BOLDITALIC(粗斜),Font.NORMAL(普通)
* @param color 字体颜色 ,如:java.awt.Color.BLACK ,Color.BLUE
* @return
*/
public Font getFont(BaseFont baseFont, float fontSize, int fontStyle, Color color){
Font font = new Font(baseFont, fontSize, fontStyle, color);
return font;
}
/**
* 取得任意对齐方式的字体
* @param str 显示字体
* @param font 字体对象
* @param i 显示位置 如左:0,中:1,右:2
* @return
*/
public Paragraph getFreeFont(String str,Font font,int i){
Paragraph par = new Paragraph(str, font);
par.setAlignment(i);
return par;
}
/**
* 取得中文基本字体(横向)
* @return
*/
public BaseFont getCnBaseFont(){
return getBaseFont(CHINA_FONT_SONGTI, ENCODE_GB);
}
/**
* 取得正常字体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.NORMAL, color);
return boldFont;
}
/**
* 取得加粗字体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnBoldFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.BOLD, color);
return boldFont;
}
/**
* 取得斜体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnItalicFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.ITALIC, color);
return boldFont;
}
/**
* 取得粗斜体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnBoldItalicFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.BOLDITALIC, color);
return boldFont;
}
/**
* 取得下划线字体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnUnderlineFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.UNDERLINE, color);
return boldFont;
}
/**
* 插入图片
* @param url
* @param imgWidth
* @param imgHeigth
* @param leftPos
* @param topPos
* @return
* @throws Exception
*/
public Image setImage(String url, float imgWidth, float imgHeigth, float leftPos, float topPos)
throws Exception {
Image img = Image.getInstance(url);
img.scaleAbsolute(imgWidth, imgHeigth);// 图片大小
img.setAbsolutePosition(leftPos, topPos);// 图片位置
return img;
}
/**
* 页眉
* @param document
* @param str
* @param flag
* @throws Exception
*/
public void setHeader(Document document, String str) throws Exception {
// 设置页眉
HeaderFooter header = new HeaderFooter(new Phrase(str,getCnFont(12,Color.black)), false);
header.setBorder(Rectangle.NO_BORDER);
header.setAlignment(Element.ALIGN_RIGHT);
document.setHeader(header);
}
/**
* 页脚
* @param document
* @param str
* @throws Exception
*/
public void setFooter(Document document, String str) throws Exception{
// 设置页脚
HeaderFooter footer = new HeaderFooter(new Phrase(str,getCnFont(8,Color.black)), true);
// 设置页脚是否有边框
// 0表示无
// 1上边框
// 2下边框
// 3上下边框都有 默认都有
footer.setBorder(0);
//footer.setBorder(1);
//footer.setBorder(2);
//footer.setBorder(3);
footer.setAlignment(Element.ALIGN_CENTER);
document.setFooter(footer);
}
/**
* pdf加密处理
* @param inputFile 文件路径
* @param outputFile 输出路径
* @param userPsw
* null或"",表示不用密码(读)
* @param ownerPsw
* null或"",表示不用密码(写)
* @param permissions ALLOW_SCREENREADERS 只读 PdfWriter.ALLOW_COPY 允许复制
* PdfWriter.ALLOW_PRINTING 允许打印,其他叁考PdfWriter常量
*/
public void encrypt(String inputFile, String outputFile, String userPsw,
String ownerPsw, int permissions) {
try {
PdfReader reader = new PdfReader(inputFile);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile));
stamper.setEncryption(userPsw.getBytes(),ownerPsw.getBytes(), permissions, false);
stamper.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
/**
* 增加水印
* @param pdfWriter
*/
public void addWaterMark(PdfWriter pdfWriter, String str, float leftPos, float topPos){
PdfContentByte over;
//under = stamp.getUnderContent(1);
//under.addImage(img);
over = pdfWriter.getDirectContentUnder();
over.beginText();
over.setFontAndSize(getBaseFont(CHINA_FONT_SONGTI,ENCODE_GB), 30);
over.showTextAligned(Element.ALIGN_LEFT, str, leftPos, topPos, 45);
over.endText();
}
}
打印pdf类ExportServletPdf.java如下:
public class ExportServletPdf extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ExportServletPdf() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.reset();
try {
// 表头
String tableHeader=request.getParameter("tableHeader");
// 表格内容
String tableBody=request.getParameter("tableBody");
// pdf共通类
CommonPdf cellutil = new CommonPdf();
// 创建文档
Document document = new Document(PageSize.A4,50,50,50,50);
// 定义字节输出流
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
// 打印pdf
PdfWriter writer = PdfWriter.getInstance(document,byteArrayOutputStream);
// 设置页眉页脚
cellutil.setHeader(document, "中华人民共和国");
cellutil.setFooter(document,"页码:");
// 打开文档
document.open();
// 标题
Font font = cellutil.getCnFont(15, Color.RED);
Paragraph par = cellutil.getFreeFont("公司开支发票", font, 1);
document.add(par);
// 获取表头
String[] head = tableHeader.split(",");
// 分隔每一行记录
String[] content = tableBody.split("@@");
// 创建表格
Table table=new Table(head.length);
table.setWidth(100);
table.setBorder(1);
table.setAlignment(Element.ALIGN_CENTER);
table.setPadding(1);
// 列名
for (int i = 0; i < head.length; i++) {
Font trFont = cellutil.getCnFont(8, Color.BLACK);
Cell cell=new Cell(new Phrase(head[i],trFont));
//cell.setUseAscender(true);
cell.setUseDescender(true);
cell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);//水平居中
cell.setVerticalAlignment(Element.ALIGN_CENTER);//垂直居中
cell.setHeader(true);
cell.setBackgroundColor(new Color(231,231,231));
cell.setVerticalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
}
table.endHeaders();
// 列值
// 循环每条记录
for (int i = 0; i < content.length; i++) {
Cell cell=null;
//取出每个单元格的值
String[] value=content[i].split("##");
for (int j = 0; j < value.length; j++) {
Font tdFont = cellutil.getCnFont(8, Color.BLACK);
cell = new Cell(new Phrase(value[j],tdFont));
//cell.setUseAscender(true); //单元格垂直对齐
cell.setUseDescender(true); //单元格水平对齐
cell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
}
}
// 添加表格
document.add(table);
// 添加图片
Image image = cellutil.setImage("D:/ad.jpg", 100, 50, 430, 420);
document.add(image);
// 添加水印
cellutil.addWaterMark(writer,"钓 鱼 岛 是 中 国 的",220,500);
// 关闭文档
document.close();
// 关闭读写流
writer.close();
// 输出pdf文件
String fileName = new String(new String(("封装打印报表" + ".pdf").getBytes("gb2312"),"ISO-8859-1"));
response.setContentType("application/pdf;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="+ fileName);
ServletOutputStream outputStream = response.getOutputStream();
byteArrayOutputStream.writeTo(outputStream);
// 加密
//cellutil.encrypt(fileName,"D:/测试pdf.pdf","123","123456789",PdfWriter.ALLOW_COPY);
//删除以前没有加密文件
/*File file =new File(fileName);
if(file.exists())
{
file.delete();
}*/
// 关闭流
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
iText-2.1.7.jar,
iTextAsian.jar,
iTextAsianCmaps.jar夹包
前台index.jsp如下:
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html; charset=utf-8" isELIgnored="false"%>
<%
String path = request.getContextPath();
%>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>欢迎来到pdf打印功能实现网站</title>
<head>
<script type="text/javascript" language="javascript" src="<%=path %>/js/jquery.js"></script>
<script type="text/javascript">
function export_report(){
var tableHeader="";
var tableBody="";
//获取表格信息
$("#tableResult tr").each(function(i,_tr){
$(_tr).children().each(function(k,_td){
if(i==0){
tableHeader+=$.trim($(_td).text())+",";
}else{
tableBody+=$.trim($(_td).text())+"##";
}
});
if(i>0){
tableBody+="@@";
}
});
if(tableHeader==""){
alert("表头未初始化!");
return false;
}
if(tableBody==""){
alert("表格体没内容!");
return false;
}
$("#report_tableHeader").val(tableHeader);
$("#report_tableBody").val(tableBody);
$("#report_form").submit();
}
</script>
</head>
<body>
<form action="#" method="post" target="_self" name="naturalPerson" id="naturalPerson">
<div class="dispaly-div" >
<table id="tableResult" width="100%" border="1" align="center" cellpadding="0" cellspacing="0" style="border-collapse: collapse;" class="sortable">
<thead>
<tr style="cursor: pointer;">
<td height="28" align="center" class="td_LTBG">户人编号</td>
<td height="28" align="center" class="td_LTBG">户编号</td>
<td height="28" align="center" class="td_LTBG">姓名</td>
<td height="28" align="center" class="td_LTBG">性别</td>
<td height="28" align="center" class="td_LTBG">现居住地</td>
<td height="28" align="center" class="td_LTBG">户籍所在地</td>
<td height="28" align="center" class="td_LTBG">身份证号码</td>
<td height="28" align="center" class="td_LTBG">出生日期</td>
<td height="28" align="center" class="td_LTBG">民族</td>
<td height="28" align="center" class="td_LTBG">文化程度</td>
<td height="28" align="center" class="td_LTBG">户口性质</td>
<td height="28" align="center" class="td_LTBG">婚姻状况</td>
</tr>
</thead>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
<td height="28" align="center" class="td_TRB">显示不下</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
<td height="28" align="center" class="td_TRB">显示</td>
</tr>
<tr>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
<td height="28" align="center" class="td_TRB">不显示</td>
</tr>
</table>
</div>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="25" align="right" class="td_RB">
<span style="margin-right: 3%;">
<a id="expor_pdf" onclick="return export_report();" style="cursor: pointer;">打印PDF</a>
</span>
</td>
</tr>
</table>
</form>
<form action="<%=path%>/ExportServletPdf" method="post" id="report_form">
<input type="hidden" name="type" id="report_type"/>
<input type="hidden" name="tableHeader" id="report_tableHeader"/>
<input type="hidden" name="tableBody" id="report_tableBody"/>
</form>
</body>
</html>
后台CommonPdf.java封装类如下:
public class CommonPdf {
private static String CHINA_FONT_SONGTI = "STSongStd-Light"; //宋体
private static String ENCODE_GB = "UniGB-UCS2-H"; // 中文编码GB(横版)
/**
* 取得基本字体
* @param font
* @param encode
* @return
*/
public BaseFont getBaseFont(String font, String encode){
BaseFont bfChinese = null;
try {
bfChinese = BaseFont.createFont(font, encode, false);
} catch (Exception e) {
e.printStackTrace();
}
return bfChinese;
}
/**
*取得具体字体
* @param baseFont 基本字体
* @param fontSize 字体大小 ,如12
* @param fontStyle 字体样式, 如com.lowagie.text.Font.BOLD(粗), Font.ITALIC(斜), Font.BOLDITALIC(粗斜),Font.NORMAL(普通)
* @param color 字体颜色 ,如:java.awt.Color.BLACK ,Color.BLUE
* @return
*/
public Font getFont(BaseFont baseFont, float fontSize, int fontStyle, Color color){
Font font = new Font(baseFont, fontSize, fontStyle, color);
return font;
}
/**
* 取得任意对齐方式的字体
* @param str 显示字体
* @param font 字体对象
* @param i 显示位置 如左:0,中:1,右:2
* @return
*/
public Paragraph getFreeFont(String str,Font font,int i){
Paragraph par = new Paragraph(str, font);
par.setAlignment(i);
return par;
}
/**
* 取得中文基本字体(横向)
* @return
*/
public BaseFont getCnBaseFont(){
return getBaseFont(CHINA_FONT_SONGTI, ENCODE_GB);
}
/**
* 取得正常字体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.NORMAL, color);
return boldFont;
}
/**
* 取得加粗字体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnBoldFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.BOLD, color);
return boldFont;
}
/**
* 取得斜体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnItalicFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.ITALIC, color);
return boldFont;
}
/**
* 取得粗斜体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnBoldItalicFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.BOLDITALIC, color);
return boldFont;
}
/**
* 取得下划线字体
* @param fontSize 字体大小 ,如12
* @param color 字体颜色 ,如Color.BLACK
* @return
*/
public Font getCnUnderlineFont(float fontSize, Color color){
BaseFont bfCn = getCnBaseFont();
Font boldFont = getFont(bfCn, fontSize, Font.UNDERLINE, color);
return boldFont;
}
/**
* 插入图片
* @param url
* @param imgWidth
* @param imgHeigth
* @param leftPos
* @param topPos
* @return
* @throws Exception
*/
public Image setImage(String url, float imgWidth, float imgHeigth, float leftPos, float topPos)
throws Exception {
Image img = Image.getInstance(url);
img.scaleAbsolute(imgWidth, imgHeigth);// 图片大小
img.setAbsolutePosition(leftPos, topPos);// 图片位置
return img;
}
/**
* 页眉
* @param document
* @param str
* @param flag
* @throws Exception
*/
public void setHeader(Document document, String str) throws Exception {
// 设置页眉
HeaderFooter header = new HeaderFooter(new Phrase(str,getCnFont(12,Color.black)), false);
header.setBorder(Rectangle.NO_BORDER);
header.setAlignment(Element.ALIGN_RIGHT);
document.setHeader(header);
}
/**
* 页脚
* @param document
* @param str
* @throws Exception
*/
public void setFooter(Document document, String str) throws Exception{
// 设置页脚
HeaderFooter footer = new HeaderFooter(new Phrase(str,getCnFont(8,Color.black)), true);
// 设置页脚是否有边框
// 0表示无
// 1上边框
// 2下边框
// 3上下边框都有 默认都有
footer.setBorder(0);
//footer.setBorder(1);
//footer.setBorder(2);
//footer.setBorder(3);
footer.setAlignment(Element.ALIGN_CENTER);
document.setFooter(footer);
}
/**
* pdf加密处理
* @param inputFile 文件路径
* @param outputFile 输出路径
* @param userPsw
* null或"",表示不用密码(读)
* @param ownerPsw
* null或"",表示不用密码(写)
* @param permissions ALLOW_SCREENREADERS 只读 PdfWriter.ALLOW_COPY 允许复制
* PdfWriter.ALLOW_PRINTING 允许打印,其他叁考PdfWriter常量
*/
public void encrypt(String inputFile, String outputFile, String userPsw,
String ownerPsw, int permissions) {
try {
PdfReader reader = new PdfReader(inputFile);
PdfStamper stamper = new PdfStamper(reader, new FileOutputStream(outputFile));
stamper.setEncryption(userPsw.getBytes(),ownerPsw.getBytes(), permissions, false);
stamper.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (DocumentException e) {
e.printStackTrace();
}
}
/**
* 增加水印
* @param pdfWriter
*/
public void addWaterMark(PdfWriter pdfWriter, String str, float leftPos, float topPos){
PdfContentByte over;
//under = stamp.getUnderContent(1);
//under.addImage(img);
over = pdfWriter.getDirectContentUnder();
over.beginText();
over.setFontAndSize(getBaseFont(CHINA_FONT_SONGTI,ENCODE_GB), 30);
over.showTextAligned(Element.ALIGN_LEFT, str, leftPos, topPos, 45);
over.endText();
}
}
打印pdf类ExportServletPdf.java如下:
public class ExportServletPdf extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ExportServletPdf() {
super();
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.reset();
try {
// 表头
String tableHeader=request.getParameter("tableHeader");
// 表格内容
String tableBody=request.getParameter("tableBody");
// pdf共通类
CommonPdf cellutil = new CommonPdf();
// 创建文档
Document document = new Document(PageSize.A4,50,50,50,50);
// 定义字节输出流
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
// 打印pdf
PdfWriter writer = PdfWriter.getInstance(document,byteArrayOutputStream);
// 设置页眉页脚
cellutil.setHeader(document, "中华人民共和国");
cellutil.setFooter(document,"页码:");
// 打开文档
document.open();
// 标题
Font font = cellutil.getCnFont(15, Color.RED);
Paragraph par = cellutil.getFreeFont("公司开支发票", font, 1);
document.add(par);
// 获取表头
String[] head = tableHeader.split(",");
// 分隔每一行记录
String[] content = tableBody.split("@@");
// 创建表格
Table table=new Table(head.length);
table.setWidth(100);
table.setBorder(1);
table.setAlignment(Element.ALIGN_CENTER);
table.setPadding(1);
// 列名
for (int i = 0; i < head.length; i++) {
Font trFont = cellutil.getCnFont(8, Color.BLACK);
Cell cell=new Cell(new Phrase(head[i],trFont));
//cell.setUseAscender(true);
cell.setUseDescender(true);
cell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);//水平居中
cell.setVerticalAlignment(Element.ALIGN_CENTER);//垂直居中
cell.setHeader(true);
cell.setBackgroundColor(new Color(231,231,231));
cell.setVerticalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
}
table.endHeaders();
// 列值
// 循环每条记录
for (int i = 0; i < content.length; i++) {
Cell cell=null;
//取出每个单元格的值
String[] value=content[i].split("##");
for (int j = 0; j < value.length; j++) {
Font tdFont = cellutil.getCnFont(8, Color.BLACK);
cell = new Cell(new Phrase(value[j],tdFont));
//cell.setUseAscender(true); //单元格垂直对齐
cell.setUseDescender(true); //单元格水平对齐
cell.setVerticalAlignment(Cell.ALIGN_MIDDLE);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setVerticalAlignment(Element.ALIGN_CENTER);
table.addCell(cell);
}
}
// 添加表格
document.add(table);
// 添加图片
Image image = cellutil.setImage("D:/ad.jpg", 100, 50, 430, 420);
document.add(image);
// 添加水印
cellutil.addWaterMark(writer,"钓 鱼 岛 是 中 国 的",220,500);
// 关闭文档
document.close();
// 关闭读写流
writer.close();
// 输出pdf文件
String fileName = new String(new String(("封装打印报表" + ".pdf").getBytes("gb2312"),"ISO-8859-1"));
response.setContentType("application/pdf;charset=utf-8");
response.setHeader("Content-Disposition", "attachment;filename="+ fileName);
ServletOutputStream outputStream = response.getOutputStream();
byteArrayOutputStream.writeTo(outputStream);
// 加密
//cellutil.encrypt(fileName,"D:/测试pdf.pdf","123","123456789",PdfWriter.ALLOW_COPY);
//删除以前没有加密文件
/*File file =new File(fileName);
if(file.exists())
{
file.delete();
}*/
// 关闭流
outputStream.flush();
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
- pdf-package.zip (4.2 MB)
- 下载次数: 2
相关推荐
本文将深入探讨如何利用C#语言和iTextSharp库,基于模板来导出PDF报表。 首先,我们需要理解iTextSharp是什么。iTextSharp是一款开源的.NET库,它允许开发者在.NET框架下创建、修改和读取PDF文件。这个库提供了丰富...
4. **导出报表**:JasperExportManager类提供了多种导出方法,如`exportReportToPdf()`, `exportReportToHtmlFile()`, 和 `exportReportToXlsFile()`,分别用于导出为PDF、HTML和Excel格式。这些方法接收JasperPrint...
在ASP.NET中,导出PDF是一项常见的需求,用于将网页内容、报表或其他数据转换为方便打印和分享的文档格式。本文将深入探讨如何在ASP.NET环境中实现PDF的导出,特别是利用wkhtmltopdf工具的方法。 PDF(Portable ...
在IT行业中,将HTML内容直接导出为PDF是一种常见的需求,尤其在报表生成、文档打印或者网络内容保存等方面。这个话题涉及到Java编程语言以及相关的库和技术。本文将深入讲解如何利用Java来实现这一功能,主要关注`...
同时,报表控件通常支持导出功能,可以将报表数据导出为PDF、Excel、CSV等常见格式,方便数据的保存和分享。 总之,"PB封装的报表"涉及了使用PowerBuilder进行应用程序开发,结合RRMReport.dll这样的报表组件,实现...
报表导出是企业级应用中常见的一项功能,它能够帮助用户将系统中的数据以结构化的形式(如 Excel 或 PDF)导出,便于进一步分析或存档。根据业务需求和技术背景的不同,报表导出可以采用多种不同的实现方式。本文将...
在实际项目中,为了简化代码和提高可维护性,你可以封装这些导出功能为服务或工具类,然后在需要的地方调用。例如,创建一个`ExportService`,其中包含`exportToExcel()`, `exportToWord()`, 和 `exportToPdf()` ...
在web开发中经常需要将jsp或html页面中表格数据导出为pdf、doc、xls等格式。然而在实现这一功能用到了一些开源的组件,每实现这一功能时都需要编写大量重复性代码。由此,对该部分进行了封装,做到通用性,在有需求...
在实际开发中,你可以封装这些功能到一个工具类中,例如 `ExportExcel.java`,并创建一个客户端类,如 `ComplexExportExcelClient.java`,以处理不同场景下的数据导出需求。这些类可能包含方法来处理数据查询、格式...
在你提供的信息中,“基于poi封装的word-excel-Pdf导出的xdoc设计”是一个使用Apache POI进行文件处理的项目,它包含了将数据导出到Word、Excel和PDF格式的功能。 1. **Apache POI**: Apache POI 是一套用于处理...
在Java编程中,生成PDF文件是一项常见的任务,特别是在需要创建报告、发票或任何其他类型的数据文档时。PDF(Portable Document Format)是一种通用的文件格式,能够保持文档的原始布局和样式,便于分享和打印。本篇...
6. **优化输出**:在导出PDF时,可以根据需要调整分辨率和压缩级别,以平衡文件大小和图像质量。此外,还可以选择是否保留链接和超链接,这对于参考文献和外部资源尤其有用。 总结来说,Cadence Capture输出带属性...
在ASP.NET环境中,我们可以利用 wkhtmltopdf.exe 来实现网页内容的导出功能,例如创建用户手册、报表或者任何需要以PDF格式呈现的文档。 首先,我们需要在ASP.NET项目中引入 wkhtmltopdf.exe 工具。通常,我们可以...
JasperReport 打印 导出PDF XLS 这是我们公司架构师搭的一套架构,封装好了打印 导出功能,其他的报表只要实现这个机制就能完成功能了,该抽象的都抽象出来了,只有一个view.jsp页面。
本组件可以将表格中的内容导出为pdf、doc、xls、jpg。 在web开发中经常需要将jsp或html页面中表格数据导出为pdf、doc、xls等格式。然而在实现这一功能用到了一些开源的组件,每实现这一功能时都需要编写大量重复性...
在Java开发中,导出Word文档是一项常见的任务,尤其在生成报表、报告或者合同等场合。本文将探讨如何使用Java高效地实现Word文档导出,主要聚焦于利用XDocReport和FreeMarker模板引擎的方式。 首先,Java中导出Word...
大家用免费的报表时,发现好多东西都需要研究,本人看了锐浪报表官方例子,真实调用时实在是用不了,因为你不可能每个报表都手工连数据库,这样数据库的连接字符串太爆露了,只好自己单独封装了一个完整的类,资源里是C# VS...
在这个“水晶报表自定义控件(导出和打印)”项目中,我们关注的是如何自定义水晶报表的导出和打印功能,使其在纯B/S(浏览器/服务器)架构下运行。 在B/S架构中,用户通过浏览器访问应用,所有的处理都在服务器端...
"导出"通常与数据的电子化传输有关,将数据从一个系统或应用程序转移到另一个地方,如Excel、PDF或其他可共享的格式。 描述中的“elx等工具类”可能是指PowerBuilder中的ELX报表,这是一种特殊的报表格式,专门用于...