1、测试例子:

需要导入的外部jar包:

相关API

http://www.coderanch.com/how-to/javadoc/itext-2.1.7/com/lowagie/text/package-summary.html

推荐博客相关参考资料:

http://www.cnblogs.com/linjiqin/p/3539283.html

 import java.awt.Color;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.URL; import javax.imageio.ImageIO; import sun.font.FontFamily; import com.lowagie.text.Cell;
import com.lowagie.text.Document;
import com.lowagie.text.Font;
import com.lowagie.text.FontFactory;
import com.lowagie.text.Image;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Row;
import com.lowagie.text.Table;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter; /**
* 导出数据:
* 输出PDF格式文件:
* Created by Jason 2016-7-17 下午5:01:41
*/
public class PrinterTest { public static void main(String[] args) { /**
* 第一步:创建PDF文档对象
*/
Document doc=new Document();
try {
/**
* 第二步:流对象的准备
*/
FileOutputStream fos= new FileOutputStream("测试pdf格式文件.pdf");
PdfWriter writer=PdfWriter.getInstance(doc,fos); /**
* 第三步:打开文档
*/
doc.open();
/**
* 第四步:设置文档信息输出属性 :下面设置的是中文字体
*/
BaseFont bf=BaseFont.createFont( "STSong-Light", //被封装过的字体类型:字体
"UniGB-UCS2-H", //pdf编码格式和pdf数据显示方向:(xxx-H)水平、(xxx-V)垂直
BaseFont.NOT_EMBEDDED); //boolean值 意义不大 Font font=new Font(bf,,Font.BOLD,Color.green); /**
* 第五步:写入文档内容
*/ /*************************【插入Table表格】******************************************/ Table table=new Table(,);//3列10行 for (int i = ; i <=; i++) {
if(i==){//列标题
table.addCell(new Cell("Name"), ,);
table.addCell(new Cell("Sex"), ,);
table.addCell(new Cell("Hobby"),,);
}else {//行数据
for (int j = ; j <=; j++) {
table.addCell(new Cell("("+i+","+j+")"), i-, j-);
}
} } table.setBorder();
table.setBorderWidthBottom();table.setBorderWidthTop();
table.setBorderColor(Color.green);
table.setBorderColorBottom(Color.red);
table.setBorderColorTop(Color.red);
table.setAlignment();//表格:0:左,1:中,2:右
table.setBackgroundColor(Color.lightGray); doc.add(table); doc.add(new Paragraph("\n\n\n"));
/*************************【插入Image图片】******************************************/
Image png = Image.getInstance("aa.png");
png.setAbsolutePosition(, );//定位原点:屏幕左下角为圆心
doc.add(png); /*************************【插入文本信息】******************************************/
doc.add(new Paragraph("\n\n\n"));
//写入样式1
Paragraph p= new Paragraph("测试标题",font);
p.setAlignment();
doc.add(p); //写入样式2 :
font.setColor(Color.red);
doc.add( new Paragraph("我是小风,我爱彦! \n 信息:123:I am Jason,I love Angle Yan!\n信息:123:I am Jason,I love Angle Yan!",
font));;//字体颜色 //提示导出成功!
System.out.println("导出成功!");
/**
* 第六步:关闭文档
*/
doc.close();
} catch (FileNotFoundException e) {
System.err.println("没有找到文档对象!");
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
 

2、测试输出:

输出样式:

导出文本、表格、图像到PDF格式文件中(学习整理)的更多相关文章

  1. JSP页面导出PDF格式文件

    JSP页面导出PDF格式文件基本在前端页面可以全部完成 <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/ ...

  2. confluence导出PDF格式文件不显示中文解决

    由于confluence导出PDF格式文件需要应用字体文件,下载字体文件在confluence管理员界面安装即可. 我这里使用从simhei.ttf楷体,可以从windowns主机里下载(c:/win ...

  3. 【NLP】Tika 文本预处理:抽取各种格式文件内容

    Tika常见格式文件抽取内容并做预处理 作者 白宁超 2016年3月30日18:57:08 摘要:本文主要针对自然语言处理(NLP)过程中,重要基础部分抽取文本内容的预处理.首先我们要意识到预处理的重 ...

  4. winform利用itextsharp.dll实现图片文件转换PDF格式文件

    1.利用itextsharp.dll实现单个图片文件转换为PDF格式文件, 可以使用以下类: void ConvertJPG2PDF(string jpgfile, string pdf) { var ...

  5. [R] venn.diagram保存pdf格式文件?

    vennDiagram包中的主函数绘图时,好像不直接支持PDF格式文件: dat = list(a = group_out[[1]][,1],b = group_out[[2]][,1]) names ...

  6. 前端实现docx、pdf格式文件在线预览

    theme: vuepress highlight: atelier-heath-light 介绍 在业务中,如果遇到文档管理类的功能,会出现需要在线预览的业务需求,本文主要是通过第三方库来实现文档预 ...

  7. mysql导出指定字段或指定数据到文件中

    使用mysqldump把mysql数据库的数据导出到文件中还是挺方便的:比如说要导出baijunyao数据库: // mysqldump -u用户名 -p 数据库名 [表名]> 导出的文件名 m ...

  8. perl练习——FASTA格式文件中序列GC含量计算&perl数组排序如何获得下标或者键

    一.关于程序: FUN:计算FASTA文件中每条序列中G和C的含量百分比,输出最大值及其id INPUT:FASTA格式文件 >seq1 CGCCGAGCGCTTGACCTCCAGCAAGACG ...

  9. 页面打开pdf格式文件的方法

    <embed width=500 height=300 fullscreen=yes src="1.pdf" />

随机推荐

  1. Interleaving String——Leetcode

    Given s1, s2, s3, find whether s3 is formed by the interleaving of s1 and s2. For example,Given:s1 = ...

  2. HW4.25

    public class Solution { public static void main(String[] args) { double sum; for(int i = 10000; i &l ...

  3. Git(一)环境搭建 + 常用命令

    上周研究了一下 Git,简单的使用了一下,个人感觉相对 SVN 来说还是有一定学习成本的,这次记录一些自己的学习过程以及常用的命令. 在学习的过程中,同事推荐了一个前辈写的教程([传送门]:Git教程 ...

  4. myeclipse building workspace如何禁止及提高myeclipse速度

    大家一定对building workspace时那缓慢的速度给困扰到了吧~ 其实只要把project选项里的 building automatically前的勾去掉,就可以快很多了.. 另外大家一定对 ...

  5. android中数据存储

    android中数据存储     Android 中存储数据的方式有五种:SQLite数据库.文件存储.内容提供者.网络.SharedPreferences(Key----value)五种存储方式. ...

  6. [每日一题] OCP1z0-047 :2013-08-12 view视图的描述哪些是正确的?

    正确答案是: CE 这是OCP教材中的: 1.简单视图与复杂视图的定义: 2.复杂视图通常不能被DML: .WITH CHECKOP TIONT选项 A不正确.简单视图可以被更新. hr@OCM> ...

  7. android81 多线程下载和断电续传

    package com.itheima.multithreaddownload; import java.io.BufferedReader; import java.io.File; import ...

  8. Coordinate System

    Coordinate System Introduction of Different Coordinate Systems Cartesian Coordinate System UI Coordi ...

  9. oracle合并查询

    1). Union 该操作符用于取得两个结果集的并集.当使用该操作符时,会自动去掉结果集中重复行. 2).union all 该操作符与union相似,但是它不会取消重复行,而且不会排序. 3). I ...

  10. WebService学习笔记系列(四)

    今天主要来看看服务端的编写及发布. 服务端的编写主要包括三个步骤: 1.编写一个接口,即SEI(server endpoint interface) 2.编写接口的实现类,即SIB (server i ...