欢迎来到淘文阁 - 分享文档赚钱的网站! | 帮助中心 好文档才是您的得力助手!
淘文阁 - 分享文档赚钱的网站
全部分类
  • 研究报告>
  • 管理文献>
  • 标准材料>
  • 技术资料>
  • 教育专区>
  • 应用文书>
  • 生活休闲>
  • 考试试题>
  • pptx模板>
  • 工商注册>
  • 期刊短文>
  • 图片设计>
  • ImageVerifierCode 换一换

    2022年2022年利用itext生成复杂pdf .pdf

    • 资源ID:39698684       资源大小:50.27KB        全文页数:7页
    • 资源格式: PDF        下载积分:4.3金币
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录   QQ登录  
    二维码
    微信扫一扫登录
    下载资源需要4.3金币
    邮箱/手机:
    温馨提示:
    快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。
    如填写123,账号就是123,密码也是123。
    支付方式: 支付宝    微信支付   
    验证码:   换一换

     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    2022年2022年利用itext生成复杂pdf .pdf

    利用 itext 生成复杂pdf 内容包括:复杂表格的生成(单元格合并,边框,位置布局,背景色)页脚输出,中文字体输出划直线下载包iText-5.0.3.jar import java.io.FileOutputStream; import java.io.IOException; import .MalformedURLException; import com.itextpdf.text.*; import com.itextpdf.text.pdf.BaseFont; import com.itextpdf.text.pdf.CMYKColor; import com.itextpdf.text.pdf.ColumnText; import com.itextpdf.text.pdf.PdfPCell; import com.itextpdf.text.pdf.PdfPTable; import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.draw.LineSeparator; public class ITextTest / public void onEndPage(PdfWriter pdfWriter, Document document) / ColumnText.showTextAligned(pdfWriter.getDirectContent(), / Element.ALIGN_CENTER,new Phrase(String.format(page %d, / 设置页码/ pdfWriter.getPageNumber(),300,50,0); / public static void main(String args) throws DocumentException, MalformedURLException, IOException / 1 、实例化文档对象Document document = new Document(PageSize.A4, 37, 30, 50, 40); / 2 、创建PdfWriter 对象 (其他编写器包括HtmlWriter 、RtfWriter 、 XmlWriter) PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(d:new.pdf); / 生成的 pdf 存放位置document.open(); / 中文字体格式/ BaseFont bfChinese = BaseFont.createFont(SIMYOU.TTF, /SIMYOU.TTF在本地目录下去拷贝C:/WINDOWS/Fonts/SIMYOU.TTF / BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED); / Font FontChinese = new Font(bfChinese, 12, Font.NORMAL); Font font1=FontFactory.getFont(FontFactory.COURIER,8, Font.BOLD,BaseColor.BLACK); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - Font font2=FontFactory.getFont(FontFactory.COURIER,8, Font.NORMAL,BaseColor.BLACK); Font font3=FontFactory.getFont(FontFactory.COURIER,9, Font.NORMAL,BaseColor.GRAY); Font font5=FontFactory.getFont(FontFactory.COURIER,8, Font.NORMAL,BaseColor.BLACK); / 设置页脚LineSeparator line=new LineSeparator(0.5f,1.3f,BaseColor.CYAN,Element.ALIGN_CENTER,0); / 直线Chunk c=new Chunk(line); /line 不能直接放入Paragraph 或 Phrase中ColumnText.showTextAligned(writer.getDirectContent(), 1,new Paragraph(String.format(Notes),font3),55,55,0);/通过坐标控制显示位置ColumnText.showTextAligned(writer.getDirectContent(), Element.ALIGN_CENTER,new Paragraph(c),300,50,0); / 设置页码/ ColumnText.showTextAligned(writer.getDirectContent(), / Element.ALIGN_CENTER,new Phrase(String.format(page %d, / writer.getPageNumber(),300,50,0); / document.newPage(); PdfPTable t = new PdfPTable(2);/创建表格t.setWidthPercentage(100);/百分比t.setSpacingBefore(20); / 表格元素1 Image image1 = Image.getInstance(1.jpg); image1.scaleAbsolute(170f, 100f);/ 宽、高PdfPCell c1 = new PdfPCell(); c1.addElement(image1); Paragraph parr=new Paragraph16; parr0 = new Paragraph(Zycoo EU,font1); parr1 = new Paragraph(LS 21 Armstrong House,First Avenue,font2); parr2 = new Paragraph(Doncaster south yorkshire DN9 3GA,font2); parr3 = new Paragraph(United Kingdom,font2); parr4 = new Paragraph(VAT GB2065852514,font2); for(int i=0;i5;i+) c1.addElement(parri); c1.setBorder(0); / 设置单元格边框的无颜色t.addCell(c1); / 表格元素2 Image image2 = Image.getInstance(2.jpg); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 2 页,共 7 页 - - - - - - - - - image2.setAlignment(Image.RIGHT); image2.scaleAbsolute(110f, 110f);/ 宽、高,值为像素PdfPCell c2 = new PdfPCell(); c2.addElement(image2); / 设置图像对齐方式c2.setBorder(0); / t.addCell(c2); / 表格元素3 parr5 = new Paragraph(Bill To,font2); parr6= new Paragraph(A Time 2 Change T/A VoIP.PT,font2); parr7= new Paragraph(Rua Consiglieri Pedroso, 123 (Iberfar),font2); parr8= new Paragraph(Edificio H ,font2); PdfPCell c3 = new PdfPCell(); c3.addElement(new Paragraph( ); for(int i=5;i8;i+) c3.addElement(parri); c3.setBorder(0); t.addCell(c3); / 元素 4 PdfPCell c4 = new PdfPCell(); c4.setBorder(0); t.addCell(c4); / 元素 5 PdfPCell c5 = new PdfPCell(); parr9= new Paragraph(Queluz de Baixo,font2); parr10= new Paragraph(2730-501 Barcarena ,font2); parr11= new Paragraph(Portugal,font2); c5.addElement(new Paragraph( ); for(int i=9;i12;i+) c5.addElement(parri); c5.setBorder(0); t.addCell(c5); / 元素 6 PdfPCell c6 = new PdfPCell(); c6.setBorder(0); t.addCell(c6); / 元素 7 PdfPCell c7 = new PdfPCell(); parr12= new Paragraph(Ship To,font2); parr13= new Paragraph(Rua Consiglieri Pedroso, 123,font2); parr14 = new Paragraph(Iberfar),font2); parr15= new Paragraph(Edificio H,font2); c7.addElement(new Paragraph( ); for(int i=12;i16;i+) c7.addElement(parri); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 3 页,共 7 页 - - - - - - - - - c7.setBorder(0); t.addCell(c7); / 元素 8 PdfPCell c8 = new PdfPCell(); PdfPTable tt = new PdfPTable(2);/向表格单项中镶嵌表格tt.getDefaultCell().setBorder(0); tt.addCell( );tt.addCell( ); tt.addCell( );tt.addCell( ); Paragraph pars=new Paragraph10; PdfPCell cells = new PdfPCell10; pars0= new Paragraph(Invoice Date :,font2); pars1=new Paragraph(09/03/2015,font2); pars2=new Paragraph(Terms :,font2); pars3=new Paragraph(Due on Receipt,font2); pars4=new Paragraph(Due Date :,font2); pars5=new Paragraph(09/03/2015,font2); pars6=new Paragraph(P.O.# :,font2); pars7=new Paragraph(EU VAT - PT507441338,font2); pars8=new Paragraph(EU VAT No. :,font2); pars9=new Paragraph(PT 507441338,font2); for(int i=0;i10;i+) parsi.setAlignment(2);/设置该段落为靠右显示cellsi=new PdfPCell(); cellsi.setBorder(0); /cell 必须有 ,再 addElement 添加才能设置对齐方式/cell1.setPhrase(para); 是错的cellsi.addElement(parsi); tt.addCell(cellsi); tt.setWidthPercentage(100);/百分比c8.addElement(tt); c8.setVerticalAlignment(Element.ALIGN_RIGHT); c8.setRowspan(2); / 向下合并单元格c8.setBorder(0); t.addCell(c8); / 元素 9 PdfPCell c9 = new PdfPCell(); Paragraph par17 = new Paragraph(Queluz de Baixo,font2); Paragraph par18 = new Paragraph(2730-501 Barcarena,font2); Paragraph par19 = new Paragraph(Portugal,font2); c9.addElement(new Paragraph( ); c9.addElement(par17); c9.addElement(par18); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共 7 页 - - - - - - - - - c9.addElement(par19); c9.setBorder(0); t.addCell(c9); / 第二张大表PdfPTable t2 = new PdfPTable(5);/创建表格int width = 8,47,10,10,25;/设置每列宽度比例t2.setWidths(width); t2.setWidthPercentage(100);/ 百分比t2.getDefaultCell().setMinimumHeight(25); t2.getDefaultCell().setBorder(0); / 设置默认最低高度(再加入空格行时候可以直接用);t2.addCell( ); 显示为默认高度/ 向第二张大表中加入元素Font font4=FontFactory.getFont(FontFactory.COURIER,8, Font.BOLD,BaseColor.WHITE); PdfPCell ccs1 = new PdfPCell55; Paragraph ppars1 = new Paragraph55; ppars100=new Paragraph(#,font4); ppars101=new Paragraph(Item & Description,font4); ppars102= new Paragraph(Qty,font4); ppars103=new Paragraph(Rate,font4); ppars104=new Paragraph(Amount,font4); ppars110=new Paragraph(1,font2); ppars111=new Paragraph(U20-A202,font2); ppars112= new Paragraph(1,00,font2); ppars113= new Paragraph(140,00,font2); ppars114=new Paragraph(140,00,font2); ppars120=new Paragraph(2,font2); ppars121=new Paragraph(2GSM,font2); ppars122=new Paragraph(1,00,font2); ppars123=new Paragraph(117,00,font2); ppars124=new Paragraph(117,00,font2); ppars130=new Paragraph(3,font2); ppars131= new Paragraph(Coofone D60,font2); ppars132= new Paragraph(5,00,font2); ppars133= new Paragraph(46,80,font2); ppars134= new Paragraph(234,00,font2); ppars140= new Paragraph(4,font2); ppars141= new Paragraph(Shipping,font2); ppars142= new Paragraph(1,00,font2); ppars143=new Paragraph(38,60,font2); ppars144=new Paragraph(38,60,font2); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 7 页 - - - - - - - - - for(int i=0;i5;i+) for(int j=0;j5;j+) ccs1ij=new PdfPCell(); if(i=0) ccs1ij.setBackgroundColor(BaseColor.DARK_GRAY); if(i=0) ccs1ij.setBorder(0);/ 无边框 else ccs1ij.setBorderColor(BaseColor.CYAN); ccs1ij.setBorder(Rectangle.BOTTOM);/设置只有下边框NO_BORDER (无边框)、 TOP上边框、 if(j=0) ccs1ij.setMinimumHeight(25);/ 设置行高 (每一行的第一个设置就OK)ppars1ij.setAlignment(1);/居中显示 else if(j=1) ppars1ij.setAlignment(0); else ppars1ij.setAlignment(2);/靠右显示 ccs1ij.addElement(ppars1ij); t2.addCell(ccs1ij); PdfPCell ccs2 = new PdfPCell52; Paragraph ppars2 = new Paragraph52; ppars200= new Paragraph(Sub Total,font2); ppars201=new Paragraph(529,60,font2); ppars210= new Paragraph(Zero Rate (0%),font2); ppars211=new Paragraph(0,00,font2); ppars220= new Paragraph(Total,font1); ppars2*2+*1+=new Paragraph(?529,60,font1);ppars230= new Paragraph(Payment Made,font2); ppars231=new Paragraph(-) 529,60,font2); ppars240= new Paragraph(Balance Due,font1); ppars2*4+*1+=new Paragraph(?0,00,font1);名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 6 页,共 7 页 - - - - - - - - - for(int i=0;i5;i+) t2.addCell(); t2.addCell(); for(int j=0;j2;j+) ccs2ij=new PdfPCell(); if(j=0) ccs2ij.setColspan(2); / 合并单元格( 2 列)ccs2ij.setBorder(0); / 无边框ppars2ij.setAlignment(2); / 靠右显示ccs2ij.addElement(ppars2ij); t2.addCell(ccs2ij); Paragraph parag =new Paragraph(, FontFactory.getFont( FontFactory.HELVETICA, 18, Font.BOLDITALIC, new CMYKColor(0, 255, 255, 17); parag.add(t); parag.add(t2); document.add(parag); document.newPage(); / 生成新页ColumnText.showTextAligned(writer.getDirectContent(), / 设置页脚Element.ALIGN_CENTER,new Paragraph(c),300,50,0); document.add(new Paragraph(Bank Details,font5); document.add(new Paragraph(Bank of Scotland, 600, GORGIE ROAD, EDINBURGH, EH11 3XP .,font5); document.add(new Paragraph(BAN - GB57BOFS80226013044960,font5); document.add(new Paragraph(Swift - BOFSGB2S,font5); document.add(new Paragraph( ); document.add(new Paragraph( ); document.add(new Paragraph(Terms & Conditions,font3); document.add(new Paragraph(Payment in advance of shipmen,font5); document.close(); 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 7 页 - - - - - - - - -

    注意事项

    本文(2022年2022年利用itext生成复杂pdf .pdf)为本站会员(C****o)主动上传,淘文阁 - 分享文档赚钱的网站仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知淘文阁 - 分享文档赚钱的网站(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    关于淘文阁 - 版权申诉 - 用户使用规则 - 积分规则 - 联系我们

    本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

    工信部备案号:黑ICP备15003705号 © 2020-2023 www.taowenge.com 淘文阁 

    收起
    展开