itextpdf-5.4.3.jar下载地址: http://www.kuaipan.cn/file/id_58980483773788178.htm
导入itextpdf-5.4.3.jar

ToPDF .java

import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.Element;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter; public class ToPDF { public static void main(String[] args) { Document document = new Document();
int ColumnNums = 6;
int CellNums = 24;
try {
// 生成PDF的绝对路径
PdfWriter.getInstance(document,
new FileOutputStream("F:\\test.pdf"));
document.open(); // 设置Table的列数
PdfPTable table = new PdfPTable(ColumnNums);
PdfPCell cell = new PdfPCell(new Paragraph("testToPDF"));
cell.setHorizontalAlignment(Element.ALIGN_CENTER); cell.setColspan(ColumnNums);
table.addCell(cell); for (int i = 0; i < CellNums; i++) {
cell = new PdfPCell(new Paragraph(i + " "));
cell.setHorizontalAlignment(Element.ALIGN_CENTER);//设置水平Alignment
cell.setVerticalAlignment(Element.ALIGN_CENTER); // 设置垂直Alignment
table.addCell(cell);
} document.add(table);
} catch (Exception e) {
e.printStackTrace();
}
document.close();
}
}

测试结果:

java生成PDF文件(itext)的更多相关文章

  1. [itext]Java生成PDF文件

    一.前言 最近在做也导出试卷的功能,刚开始是导出为doc,可是导出来格式都有变化,最后说直接将word转为pdf,可是各种不稳定,各种报错.最后想到直接将文件写入pdf(参考:http://www.c ...

  2. JAVA生成PDF文件

    生成PDF文件是主要应用的是ITEXT插件 import java.awt.Color; import java.io.File; import java.io.FileOutputStream; i ...

  3. Java生成PDF文件(转)

    原文地址:https://www.cnblogs.com/shuilangyizu/p/5760928.html 一.前言 前几天,做ASN条码收货模块,需要实现打印下载收货报表,经一番查找,选定iT ...

  4. java生成pdf文件 --- Table

    Java利用itext实现导出PDF文件 所需要的jar包:com.lowagie.text_2.1.7.v201004222200.jar jar包下载地址:http://cn.jarfire.or ...

  5. 【文件】java生成PDF文件

    package test; import java.awt.Color; import java.io.FileOutputStream; import org.junit.Test; import ...

  6. java调用wkhtmltopdf生成pdf文件,美观,省事

    最近项目需要导出企业风险报告,文件格式为pdf,于是搜了一大批文章都是什么Jasper Report,iText ,flying sauser ,都尝试了一遍,感觉不是我想要的效果, 需要自己调整好多 ...

  7. Java 生成pdf表格文档

    最近在工作做一个泰国的项目,应供应商要求,需要将每天的交易生成pdf格式的报表上传到供应商的服务器,特此记录实现方法.废话不多说,直接上代码: THSarabunNew.ttf该文件是泰国字体自行网上 ...

  8. Java Itext 生成PDF文件

    利用Java Itext生成PDF文件并导出,实现效果如下: PDFUtil.java package com.jeeplus.modules.order.util; import java.io.O ...

  9. Itext生成pdf文件

    来源:https://my.oschina.net/lujianing/blog/894365 1.背景 在某些业务场景中,需要提供相关的电子凭证,比如网银/支付宝中转账的电子回单,签约的电子合同等. ...

随机推荐

  1. ios结构体httpPost头结构

    ios结构体httpPost头结构 by 吴雪莹 NSString* urlStr = @"; NSURL* url = [NSURL URLWithString:urlStr]; NSMu ...

  2. 【百度地图API】如何制作泡泡放大镜?

    原文:[百度地图API]如何制作泡泡放大镜? 任务描述: 我不喜欢API提供的缩放控件耶…… 我能不能使用其他方式放大地图勒? 当然阔以啦! 现在就来教大家如何动手制作一个可爱的泡泡放大镜! 使用它, ...

  3. 让你的Windows不断重启的C语言代码

    原文:让你的Windows不断重启的C语言代码 没有写Linux的原因是因为搞不定Linux下的权限问题,而Windows下基本上使用电脑的用户都是管理员,所以钻个空了,不多说下面是代码#includ ...

  4. IOS发展--他们控制的定义

    有没有这样的要求,,自定义panel,里面放几个控件,在多个页面中使用此panel. 有三个观点来解决这个问题: 1.自己继承UIView写一个类,在它是在代码的形式加入需要控制.完成布局. 2.使用 ...

  5. 探讨css中repaint和reflow

    (个人blog迁移文章.) 前言: 页面设计中,不可避免的需要浏览器进行repaint和reflow.那到底什么是repaint和reflow呢.下面谈谈自己对repaint和reflow的理解,以及 ...

  6. Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by

    配置php网站的时候,经常会在页首出现Warning: session_start() [function.session-start]: Cannot send session cache limi ...

  7. Linux忘记rootpassword

    我们常常会碰到忘记rootpassword的情况,以下是解决之道,  此方法使用绝大多数的Linux发行版:  1. 首先进入grub  2. 在须要编辑的入口处,按下e,在quite后增加     ...

  8. leetcode第33题--Search for a Range

    Given a sorted array of integers, find the starting and ending position of a given target value. You ...

  9. Failed to issue method call: Unit mysql.service failed to load: No such file or directory解决的方式

    Failed to issue method call: Unit mysql.service failed to load: No such file or directory解决的方式 作者:ch ...

  10. Ibatis配置存储过程xml文件案例

    -- <parameterMaps> <!--注意:parameterMap中的参数个数和顺序要和ProcGetPersonByName存储过程中的一致--> <para ...