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报表的更多相关文章

  1. Java生成PDF报表

    一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iText--用于生成PDF文档的一个Java类库.废话不多说,进入正题. 二.iText简介 iText是著名的开放 ...

  2. JAVA 生成PDF报表()

    许多应用程序都要求动态生成 PDF 文档.这些应用程序涵盖从生成客户对帐单并通过电子邮件交付的银行到购买特定的图书章节并以 PDF 格式接收这些图书章节的读者.这个列表不胜枚举.在本文中,我们将使用 ...

  3. 使用JSP页面生成PDF报表

    转自:http://developer.51cto.com/art/200907/134261.htm 1.iText简介 iText是一个开放源码的Java类库,可以用来方便地生成PDF文件.大家通 ...

  4. java生成PDF,并下载到本地

    1.首先要写一个PDF工具类,以及相关工具 2.PDF所需jar包 iText是一种生成PDF报表的Java组件 freemarker是基于模板来生成文本输出 <dependency> & ...

  5. Java 生成pdf表格文档

    最近在工作做一个泰国的项目,应供应商要求,需要将每天的交易生成pdf格式的报表上传到供应商的服务器,特此记录实现方法.废话不多说,直接上代码: THSarabunNew.ttf该文件是泰国字体自行网上 ...

  6. [.NET开发] C#使用doggleReport生成pdf报表的方法

    本文实例讲述了C#使用doggleReport生成pdf报表的方法.分享给大家供大家参考,具体如下: 1. 安装nuget -install package DoddleReport -install ...

  7. Java生成PDF文件(转)

    原文地址:https://www.cnblogs.com/shuilangyizu/p/5760928.html 一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iT ...

  8. [itext]Java生成PDF文件

    一.前言 最近在做也导出试卷的功能,刚开始是导出为doc,可是导出来格式都有变化,最后说直接将word转为pdf,可是各种不稳定,各种报错.最后想到直接将文件写入pdf(参考:http://www.c ...

  9. JAVA生成PDF文件

    生成PDF文件是主要应用的是ITEXT插件 import java.awt.Color; import java.io.File; import java.io.FileOutputStream; i ...

随机推荐

  1. 【POJ1470】Closest Common Ancestors

    Description Write a program that takes as input a rooted tree and a list of pairs of vertices. For e ...

  2. Bluetooth Low Energy 介绍

    1.简介 BLE(Bluetooth Low Energy,低功耗蓝牙)是对传统蓝牙BR/EDR技术的补充.尽管BLE和传统蓝牙都称之为蓝牙标准,且共享射频,但是,BLE是一个完全不一样的技术.BLE ...

  3. MSbuild 教程

    在.Net framework中,一个不太被大家熟知的工具就是MSBuild.这个命令行工具通过执行XML脚本可以自动生成软件工程文件. 但问题来了,“我为什么想要我的生成过程自动化?”. 其实,大部 ...

  4. Light OJ 1032 - Fast Bit Calculations(数位DP)

    题目大意: 一个数字把他看成二进制数字,数字里又会一些相邻的1,问从0到n至间所有相邻1的总和是多少?   分解成2进制数字,然后数位DP就行了.   ======================== ...

  5. 【转】VC的MFC中重绘函数的使用总结(整理)

    原文网址:http://www.cnblogs.com/x8023z/archive/2008/12/09/mfc33.html 在刷新窗口时经常要调用重绘函数MFC提供了三个函数用于窗口重绘Inva ...

  6. 利用腾讯企业邮箱开放API获取账户未读邮件数初探

    公司一直使用腾讯提供的免费企业邮箱服务,今天用管理员帐户登录后发现,原来现在腾讯的企业邮箱也开放了部分API 你可以通过开放接口实现以下功能: 数据同步 数据同步可以帮助你同步部门成员信息,你还可以创 ...

  7. 编译android的linux kernel goldfish

    https://source.android.com/source/building-kernels.html $ export PATH=/home/hzh/oldhome/learn/androi ...

  8. 使用Spring-data-redis操作Redis的Sentinel

    介绍 Spring-Data-Redis项目(简称SDR) 是对Redis的Key-Value数据存储操作提供了更高层次的抽象,提供了一个对几种主要的redis的Java客户端(例 如:jedis,j ...

  9. JDK JRE JVM

    使用java很久,但是一直不清楚JDK,JRE,JVM直接的关系,今天特地梳理一下. JDK:Java Development ToolKit(Java开发工具包),JDK是整个JAVA的核心,包括J ...

  10. springboot +spring security4 +thymeleaf 后台管理系统

    需求:一个后台管理系统,现在用的springboot 微框架比较多, 所以这里也使用了, 后台权限用 spring security ,之前以前觉得听复杂 . 后来发现还是蛮简单的, 看了源代码之后. ...