* Title: 通过itext 包生成PDF 文件 *
** Description: *
** Copyright: Copyright (c) 2003 *
** Filename: PDFOpr.java *
* * @version 1.0 */ public class PDFOpr { public static void main(String[] args) { String pdfPath = "D:/test.pdf"; createPDF(pdfPath); } public static void createPDF(String pdfPath) { //Document(Rectangle pageSize, float marginLeft, float marginRight, float marginTop, float marginBottom) Document document = new Document(PageSize.A4.rotate(), 18f, 18f, 18f, 10f); try { System.out.println("Generating PDF"); PdfWriter.getInstance(document, new FileOutputStream(pdfPath)); document.open(); BaseFont bfChinese = BaseFont.createFont("STSongStd-Light", "UniGB-UCS2-H", false); Font fontChinese = new Font(bfChinese); fontChinese.setSize(10f); Font fontChinese2 = new Font(bfChinese); fontChinese2.setSize(7f); float[] widths = {4f,260,10f,260,10f,260f,4f}; //new 一个13 列的table PdfPTable table = new PdfPTable(7); //设置table 每一列的宽度,widths 里写的是百分比,他们加和需要是1 table.setWidths(widths); //设置表格在页面上的宽度,设成100 表示可以表格填满页面,但是要去掉页面margin table.setWidthPercentage(100); //设置表格上端的空白距离,类似css 中的margin-top:xxpx;这样在给表格加上标题后,标题就不会跟表格重叠在一起了。 table.setSp...1、当您付费下载文档后,您只拥有了使用权限,并不意味着购买了版权,文档只能用于自身使用,不得用于其他商业用途(如 [转卖]进行直接盈利或[编辑后售卖]进行间接盈利)。
2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。
3、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。
碎片内容