资源描述:
《利用itext生成复杂pdf》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、利用itext生成复杂pdf内容包括:复杂表格的生成(单元格合并,边框,位置布局,背景色)页脚输出,中文字体输出划直线下载包iText-5.0.3.jarimportjava.io.FileOutputStream;importjava.io.IOException;importjava.net.MalformedURLException;importcom.itextpdf.text.*;importcom.itextpdf.text.pdf.BaseFont;importcom.itextpdf.text.pdf.CMYKColor;importcom.itextpdf.text.pdf
2、.ColumnText;importcom.itextpdf.text.pdf.PdfPCell;importcom.itextpdf.text.pdf.PdfPTable;importcom.itextpdf.text.pdf.PdfWriter;importcom.itextpdf.text.pdf.draw.LineSeparator;publicclassITextTest{//publicvoidonEndPage(PdfWriterpdfWriter,Documentdocument){//ColumnText.showTextAligned(pdfWriter.getDirec
3、tContent(),//Element.ALIGN_CENTER,newPhrase(String.format("page%d",//设置页码//pdfWriter.getPageNumber())),300,50,0);//}publicstaticvoidmain(String[]args)throwsDocumentException,MalformedURLException,IOException{//1、实例化文档对象Documentdocument=newDocument(PageSize.A4,37,30,50,40);//2、创建PdfWriter对象(其他编写器包括H
4、tmlWriter、RtfWriter、XmlWriter)PdfWriterwriter=PdfWriter.getInstance(document,newFileOutputStream("d:ew.pdf"));//生成的pdf存放位置document.open();//中文字体格式//BaseFontbfChinese=BaseFont.createFont("SIMYOU.TTF",//SIMYOU.TTF在本地目录下去拷贝C:/WINDOWS/Fonts/SIMYOU.TTF//BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);//Fo
5、ntFontChinese=newFont(bfChinese,12,Font.NORMAL);Fontfont1=FontFactory.getFont(FontFactory.COURIER,8,Font.BOLD,BaseColor.BLACK);Fontfont2=FontFactory.getFont(FontFactory.COURIER,8,Font.NORMAL,BaseColor.BLACK);Fontfont3=FontFactory.getFont(FontFactory.COURIER,9,Font.NORMAL,BaseColor.GRAY);Fontfont5=F
6、ontFactory.getFont(FontFactory.COURIER,8,Font.NORMAL,BaseColor.BLACK);//设置页脚LineSeparatorline=newLineSeparator(0.5f,1.3f,BaseColor.CYAN,Element.ALIGN_CENTER,0);//直线Chunkc=newChunk(line);//line不能直接放入Paragraph或Phrase中ColumnText.showTextAligned(writer.getDirectContent(),1,newParagraph(String.format("N
7、otes"),font3),55,55,0);//通过坐标控制显示位置ColumnText.showTextAligned(writer.getDirectContent(),Element.ALIGN_CENTER,newParagraph(c),300,50,0);//设置页码//ColumnText.showTextAligned(writer.getDirectContent(),//Element.