六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 29|回复: 0

IText 生成PDF

[复制链接]

升级  2%

13

主题

13

主题

13

主题

秀才

Rank: 2

积分
53
 楼主| 发表于 2013-1-15 02:54:10 | 显示全部楼层 |阅读模式
public static writePDF(){Document document = new Document(); FileOutputStream os = new FileOutputStream(new File(Const.FILE_IN + File.separator + foldPath + File.separator + fileName));PdfWriter.getInstance(document, os);document.open(); BaseFont bfChinese = BaseFont.createFont("STSong-Light","UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);//加入document: ; Font FontChineseB = new Font(bfChinese, 12, Font.BOLD);//加入document:Image png = Image.getInstance(Const.FILE_PROCECT + File.separator + "images" + File.separator + "pdf_head.jpg");//图片的地址 document.add(png);Paragraph head = new Paragraph("预定通知单  订单号:" + String.valueOf(hotelChOrder.getId()), FontChineseB);head.setAlignment(Element.ALIGN_CENTER);document.add(head); MemberDomain memberDomain = (MemberDomain)BeanFactory.getDomain(Const.MEMBER_DOMAIN);memberDomain.initByMemberId(TypeParse.str2Long(vo.getHotelMemberId()));UserDomain userDomain = (UserDomain)BeanFactory.getDomain(Const.USER_DOMAIN);userDomain.initByMemberUserId(memberDomain.getMember().getManager());document.add(new Paragraph("To:"+memberDomain.getMember().getMemberCn()+"  联系人:"+userDomain.getMemberUser().getUserName()+"("+userDomain.getMemberUser().getMobile()+")  预定时间:"+systemDate, FontChinese));document.add(new Paragraph("Tel:"+memberDomain.getMember().getTel()+"  Fax:"+memberDomain.getMember().getFax()+"", FontChinese));Table pdfLine = new Table(1,1);pdfLine.setBorderColor(new Color(0, 0, 0));pdfLine.setBorderWidth(1);pdfLine.setWidth(100);Cell lineCell = new Cell(new Paragraph("", FontChinese)); pdfLine.addCell(lineCell); document.add(pdfLine);Table details = new Table(2,9);details.setBorderColor(new Color(255, 255, 255));details.setBorderWidth(0);details.setBorder(0);details.setWidth(80);int width[] = {20,60};details.setWidths(width);details.setPadding(0);Paragraph leftCellParagraph = new Paragraph("客人姓名:", FontChineseB);leftCellParagraph.setAlignment(Element.ALIGN_RIGHT);Cell detailsCell = new Cell(leftCellParagraph); detailsCell.setBorderColor(new Color(255, 255, 255));detailsCell.setBorder(0);detailsCell.setBorderWidth(0);details.addCell(detailsCell);String usernames = hotelChOrder.getUserList().replaceAll(";", ",");Paragraph rightCellParagraph = new Paragraph(usernames, FontChinese);rightCellParagraph.setAlignment(Element.ALIGN_LEFT);detailsCell = new Cell(rightCellParagraph); detailsCell.setBorderColor(new Color(255, 255, 255));detailsCell.setBorder(0);detailsCell.setBorderWidth(0);details.addCell(detailsCell); leftCellParagraph = new Paragraph("住房日期:", FontChineseB);leftCellParagraph.setAlignment(Element.ALIGN_RIGHT);detailsCell = new Cell(leftCellParagraph); detailsCell.setBorderColor(new Color(255, 255, 255));detailsCell.setBorder(0);detailsCell.setBorderWidth(0);details.addCell(detailsCell); rightCellParagraph = new Paragraph(vo.getCheckInDate() + " 至 "+vo.getCheckOutDate()+" 共"+vo.getDays()+"晚", FontChinese);rightCellParagraph.setAlignment(Element.ALIGN_LEFT);detailsCell = new Cell(rightCellParagraph); detailsCell.setBorderColor(new Color(255, 255, 255));detailsCell.setBorder(0);detailsCell.setBorderWidth(0);details.addCell(detailsCell); leftCellParagraph = new Paragraph("预定客房:", FontChineseB);leftCellParagraph.setAlignment(Element.ALIGN_RIGHT);detailsCell = new Cell(leftCellParagraph); detailsCell.setBorderColor(new Color(255, 255, 255));detailsCell.setBorder(0);detailsCell.setBorderWidth(0);details.addCell(detailsCell); document.add(details);document.close();  }
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表