java 生成pdf报表
public void saveMapAddressInfo(String orderCode){
try{
List<Leads> leadses = leadsService.findLeadsByCode(orderCode);
if (leadses != null && leadses.size() > 0){
//创建Document实例
Document document = new Document(PageSize.A4, 20, 20, 20, 20);
//建立一个书写器(Writer)与document对象关联,通过书写器(Writer)可以将文档写入到磁盘中。
PdfWriter.getInstance(document, new FileOutputStream(this.filePath + "/" + orderCode+"-MapUserInfo.pdf"));
//打开文档。
document.open();
Font cellFont = FontFactory.getFont("HELVETICA", 9, BaseColor.BLACK);
Font titleFont = FontFactory.getFont("HELVETICA-BOLD", 9, BaseColor.BLACK);
PdfPTable table = new PdfPTable(8);
PdfPCell cell;
table.setWidthPercentage(100);
table.setWidths(new int[]{3, 4, 4, 5, 3, 3, 2, 3});
table.getDefaultCell().setUseAscender(true);
table.getDefaultCell().setUseDescender(true);
// first row
cell = new PdfPCell(new Phrase(orderCode + " - Map User Info"));
cell.setColspan(8);
cell.setHorizontalAlignment(Element.ALIGN_CENTER);
cell.setPadding(5.0f);
cell.setBackgroundColor(new BaseColor(53,168,3));
cell.setMinimumHeight(30);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Name",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Phone",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Email",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Address",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("Address2",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("City",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("State",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph("ZipCode",titleFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
for(Leads leads:leadses){
cell = new PdfPCell(new Paragraph(leads.getFirstName()+" "+leads.getLastName(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(leads.getPhone(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(leads.getEmail(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(leads.getAddress(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(leads.getAddress2(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(leads.getCity(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(leads.getState(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
cell = new PdfPCell(new Paragraph(leads.getZipCode(),cellFont));
cell.setPadding(5.0f);
cell.setMinimumHeight(25);
table.addCell(cell);
}
//向文档中添加内容。
document.add(table);
// 5.关闭文档
document.close();
}
}catch (FileNotFoundException e){
e.printStackTrace();
}catch (DocumentException e){
e.printStackTrace();
}
}
java 生成pdf报表的更多相关文章
- Java生成PDF报表
一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iText--用于生成PDF文档的一个Java类库.废话不多说,进入正题. 二.iText简介 iText是著名的开放 ...
- JAVA 生成PDF报表()
许多应用程序都要求动态生成 PDF 文档.这些应用程序涵盖从生成客户对帐单并通过电子邮件交付的银行到购买特定的图书章节并以 PDF 格式接收这些图书章节的读者.这个列表不胜枚举.在本文中,我们将使用 ...
- 使用JSP页面生成PDF报表
转自:http://developer.51cto.com/art/200907/134261.htm 1.iText简介 iText是一个开放源码的Java类库,可以用来方便地生成PDF文件.大家通 ...
- java生成PDF,并下载到本地
1.首先要写一个PDF工具类,以及相关工具 2.PDF所需jar包 iText是一种生成PDF报表的Java组件 freemarker是基于模板来生成文本输出 <dependency> & ...
- Java 生成pdf表格文档
最近在工作做一个泰国的项目,应供应商要求,需要将每天的交易生成pdf格式的报表上传到供应商的服务器,特此记录实现方法.废话不多说,直接上代码: THSarabunNew.ttf该文件是泰国字体自行网上 ...
- [.NET开发] C#使用doggleReport生成pdf报表的方法
本文实例讲述了C#使用doggleReport生成pdf报表的方法.分享给大家供大家参考,具体如下: 1. 安装nuget -install package DoddleReport -install ...
- Java生成PDF文件(转)
原文地址:https://www.cnblogs.com/shuilangyizu/p/5760928.html 一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iT ...
- [itext]Java生成PDF文件
一.前言 最近在做也导出试卷的功能,刚开始是导出为doc,可是导出来格式都有变化,最后说直接将word转为pdf,可是各种不稳定,各种报错.最后想到直接将文件写入pdf(参考:http://www.c ...
- JAVA生成PDF文件
生成PDF文件是主要应用的是ITEXT插件 import java.awt.Color; import java.io.File; import java.io.FileOutputStream; i ...
随机推荐
- NOR FLASH与NAND FLASH
整理自NOR FLASH 与NAND FLASH 1:NandFlash与NorFlash典型电路图 Nor Flash接原理图 从上图可以看出,该NorFlash采用并行地址和数据总线, 其中,21 ...
- Children's Day
hdu4706:http://acm.hdu.edu.cn/showproblem.php?pid=4706 题意:让你打出3--10的N,这个N是由连续的小写字母组成的. 题解:直接模拟啊,水题啊. ...
- java基础随笔-内部类
今天来复习下内部类的一些基础知识. 首先是内部类的分类: 1.成员内部类 2.静态内部类 3.匿名内部类 4.局部内部类 下面逐一来介绍下. 首先是成员内部类,就是将内部类作为一个成员变量来处理.具体 ...
- bzoj3504
这是一道最大流的题目首先要引起注意的是,这类多个起点多个终点的问题一定要同时跑,不能分开来跑由于是无向图,也就相当于从起点跑2*n次好,不难想到s向两个起点连边,两终点想t连边,流量为2*an或2*b ...
- Linux学习笔记30——套接字
一 什么是套接字 套接字是一种通信机制,凭借这种机制,客户/服务器系统的开发既可以在本地单机上进行,也可以跨网络进行. 二 套接字属性 套接字的特性由3个属性确定,它们是:域,类型和协议 1 套接 ...
- iptables vpn
- openStack 性能开测-2
- Kong for Enterprise | Kong - Open-Source API and Microservice Management Layer
Kong for Enterprise | Kong - Open-Source API and Microservice Management Layer undefined
- 从物理执行的角度透视spark Job
本博文主要内容: 1.再次思考pipeline 2.窄依赖物理执行内幕 3.宽依赖物理执行内幕 4.Job提交流程 一:再次思考pipeline 即使采用pipeline的方式,函数f对依赖的RDD中 ...
- sBPM产品介绍
作者:CppExplore http://www.cppblog.com/CppExplore/和 http://blog.csdn.net/cppexplore同步发布. 近3年没发文章,谨以本 ...