表格生成pdf
来源:互联网 发布:蚁群算法 旅行商问题 编辑:程序博客网 时间:2024/06/05 08:08
public class PdfSomainUtil { public static void main(String[] args) { String[] str1= {"沈阳有限公司1", "1234561", "1元/kg", "大米", "123456", "A12仓","500件","10000Kg","2000Kg","8000Kg","8000Kg","100","100","无意见1","d:/dossp/pdf/1.jpg"}; String[] str2 = {"虎林有限公司2", "1234562", "1元/kg", "大米", "虎123456", "A12仓","500件","10000Kg","2000Kg","8000Kg","8000Kg","100","100","无意见2","d:/dossp/pdf/2.jpg"}; String[] str3= {"合肥有限公司3", "1234563", "1元/kg", "大米", "皖123456", "A12仓","500件","10000Kg","2000Kg","8000Kg","8000Kg","100","100","无意见3","d:/dossp/pdf/111.jpg"}; String[] str4 = {"唐山有限公司4", "1234564", "1元/kg", "大米", "冀123456", "A12仓","500件","10000Kg","2000Kg","8000Kg","8000Kg","100","100","无意见4","d:/dossp/pdf/111.jpg"}; String[] str5 = {"富平有限公司5", "1234565", "1元/kg", "大米", "陕123456", "A12仓","500件","10000Kg","2000Kg","8000Kg","8000Kg","100","100","无意见5","d:/dossp/pdf/5.jpg"}; java.util.List list=new ArrayList(); list.add(str1); list.add(str2); list.add(str3); list.add(str4); list.add(str5); int count = list.size();// 总记录数 int pageCount = 4;// 每页记录数 int page = page=list.size()/4;// 总共页数 if(list.size()%4 != 0){ page=list.size()/4 +1; } File file = new File("d:/dossp/itext.pdf");//生成pdf名称及路径 Document document = new Document(PageSize.A4); BaseFont bf = null; Font fontChinese = null; Font fontChar = new Font(); fontChar.setSize(7); fontChar.setColor(BaseColor.DARK_GRAY); FileOutputStream out=null; try { bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); fontChinese = new Font(bf, 10, Font.NORMAL);// 中文字体 fontChinese.setSize(10);//字体大小 out=new FileOutputStream(file); PdfWriter pdfWriter = PdfWriter.getInstance(document, out);// 文档输出流。 document.open(); int k=0; for (int item = 0; item < page; item++) {// 页数 document.newPage(); int times=pageCount; if((page-item)==1 && list.size()%4!=0){ times=list.size()-item*4; } for(int j=0;j<times;j++){ //每页循环次数 String[] model=(String[]) list.get(k); PdfPTable table = new PdfPTable(new float[]{23, 35, 23, 35, 80}); table.setTotalWidth(600); PdfPCell cell = new PdfPCell(new Phrase("单位:", fontChinese)); PdfPCell cell1 = new PdfPCell(new Phrase(model[0], fontChinese)); cell1.setColspan(3); table.addCell(cell); table.addCell(cell1); Image image = Image.getInstance(model[14]); image.scaleAbsolute(170f, 124f); image.setAlignment(Image.MIDDLE); PdfPCell cell_img = new PdfPCell(image); cell_img.setRowspan(9); table.addCell(cell_img); table.addCell(new Paragraph("合同号:", fontChinese)); table.addCell(new Paragraph(model[1], fontChinese)); table.addCell(new Paragraph("合同单价:", fontChinese)); table.addCell(new Paragraph(model[2], fontChinese)); table.addCell(new Paragraph("品名:", fontChinese)); table.addCell(new Paragraph(model[3], fontChinese)); table.addCell(new Paragraph("车号:", fontChinese)); table.addCell(new Paragraph(model[4], fontChinese)); table.addCell(new Paragraph("仓号", fontChinese)); table.addCell(new Paragraph(model[5], fontChinese)); table.addCell(new Paragraph("件数:", fontChinese)); table.addCell(new Paragraph(model[6], fontChinese)); table.addCell(new Paragraph("重车:", fontChinese)); table.addCell(new Paragraph(model[7], fontChinese)); table.addCell(new Paragraph("空车:", fontChinese)); table.addCell(new Paragraph(model[8], fontChinese)); table.addCell(new Paragraph("净重:", fontChinese)); table.addCell(new Paragraph(model[9], fontChinese)); table.addCell(new Paragraph("结算:", fontChinese)); table.addCell(new Paragraph(model[10], fontChinese)); table.addCell(new Paragraph("容重", fontChinese)); table.addCell(new Paragraph(model[11], fontChinese)); table.addCell(new Paragraph("扣:", fontChinese)); table.addCell(new Paragraph(model[12], fontChinese)); PdfPCell cell_rong = new PdfPCell(new Phrase("采购意见:", fontChinese)); PdfPCell cell_rongVal = new PdfPCell(new Phrase(model[13], fontChinese)); cell_rong.setFixedHeight(25); cell_rong.setRowspan(2); cell_rongVal.setColspan(3); cell_rongVal.setRowspan(2); table.addCell(cell_rong); table.addCell(cell_rongVal); table.setSpacingAfter(30); document.add(table); k++; } } pdfWriter.flush(); document.close(); } catch (DocumentException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }}
阅读全文
0 0
- C#生成PDF表格
- 表格生成pdf
- Java生成pdf中的表格
- 使用 iTextSharp 生成 PDF 表格
- Java iText 生成PDF表格
- JAVA 生成一个表格的 PDF文件
- pdf数据表格的生成与导出
- java生成pdf文件包含表格
- 使用reportlab生成中文表格pdf
- django学习之 pdf报表(表格)生成
- java 如何在pdf中生成表格
- itext 导出pdf 表格生成、目录生成、支持中文
- PDF表格
- Java生成PDF文档(表格、列表、添加图片等)
- Java iText 动态 生成 PDF 文档表格中文问题
- java代码生成PDF文件-表格和图片
- 生成PDF文件-使用iText制作复杂表格
- jasperreport生成html,Excel,PDF表格,数据源使用List
- 微信日常小记-error48001
- Spring整合Hibernate使用懒加载报错Could not initialize proxy
- Eclipse背景色、主题、字体设置
- Mybatis JPA-集成方案+源码
- 结构型-桥接模式(Bridge)
- 表格生成pdf
- word标题不自动编号
- 开发手记--使用OkHttp忽略HTTPS验证
- 51.多皇后问题
- 数据结构实验之二叉树二:遍历二叉树
- springboot(十四):springboot整合shiro-登录认证和权限管理
- Codeforces 821E Okabe and El Psy Kongroo(Dp+矩阵快速幂)
- 一步一步学SpringDataJpa——JpaRepository查询功能
- Maven 进阶--- 引用lib下的本地jar