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 ...
随机推荐
- Android应用程序的生命周期
转自Android应用程序的生命周期 在对一个简单的Hello World工程进行项目结构剖析后,我们接着来学习下一个Android应用程序的生命周期是怎么样的,以便为后面的开发有个垫下良好的基石~ ...
- OTG线与普通USB线的区别
转自OTG线与普通USB线的区别 USB数据线是我们常见的设备,OTG线作为近年来随着手机行业的快速发展,逐步进入了我们的日常使用范围.OTG线与普通USB线的有什么区别? USB数据线用 ...
- Two shortest
sgu185:http://acm.sgu.ru/problem.php?contest=0&problem=185 题意:找两条最短路径,没有边相交的最短路劲,并且输出路径. 题解:这一题和 ...
- android中保存一个ArrayList到SharedPreferences的方法
保存: public static boolean saveArray() { SharedPrefernces sp=SharedPrefernces.getDefaultSharedPrefern ...
- 【HDOJ】1556 Color the ball
简单线段树. #include <stdio.h> #define MAXN 100005 #define lson l, mid, rt<<1 #define rson mi ...
- bzoj1455
学习了一下可合并堆的一种写法——左偏树感觉左偏树是一种类似启发式的方法学习左偏树后这题就水过去了 ..] of longint; v:..] of boolean; i,n,m,x,y,f:longi ...
- bzoj2653
CLJ神牛的可持久化论文的题目,果然厉害其实第一步能想到后面就还是很简单的首先是二分答案,转化为判定性问题然后对于区间内的数,比他大的标为1,小的标为-1显然,如果存在一个左右端点符合的区间使得这个区 ...
- unity3d Realistic eye shading 真实的眼睛渲染
先放上效果 人皮都做了,当然要来研究下眼睛,眼睛要比人体皮肤简单一些(实时模拟人皮在此) 一看是不是很复杂 这是眼睛的解构,但是,我们只需要模拟出虹膜巩膜和角膜就能达到相当真实的眼睛 巩膜就是白眼球 ...
- orace owi介绍
第1章 OWI介绍记录和观察进程所经历的等待现象的功能和界面以及方法论,统称为OWI,也就是Oracle Wait Interface.等待事件的P1.P2.P3值可以通过v$session_wait ...
- U3D C# 实现AS3事件机制
写了很多年的AS3,最近接触U3D感觉事件机制没AS3的爽.咬紧牙关一鼓作气 基于C# 的委托实现了一版.废话不多说上干货. EventDispatcher代码如下: using UnityEngin ...