📄 hello.java
字号:
package lee;
import java.io.FileOutputStream;
import java.io.IOException;
import java.awt.Color;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;
import com.lowagie.text.pdf.BaseFont;
/**
* @author yeeku.H.lee kongyeeku@163.com
* @version 1.0
* <br>Copyright (C), 2005-2008, yeeku.H.Lee
* <br>This program is protected by copyright laws.
* <br>Program Name:
* <br>Date:
*/
public class Hello
{
public static void main(String[] args)throws Exception
{
BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
Font FontChinese = new Font(bfChinese, 12, Font.NORMAL);
// 第一步,创建document对象
Rectangle rectPageSize = new Rectangle(PageSize.A4);
//rectPageSize = rectPageSize.rotate();
Document doc = new Document(rectPageSize,50,50,50,50);
Document document = new Document();
try
{
// 将Document实例和文件输出流用PdfWriter类绑定在一起
//从而完成向Document写,即写入PDF文档
PdfWriter.getInstance(document,new FileOutputStream("HelloWorld.pdf"));
//打开文档
document.open();
//文档由段组成
document.add(new Paragraph("Hello World"));
Paragraph par = new Paragraph("世界你好",FontChinese);
document.add(par);
PdfPTable table = new PdfPTable(3);
for(int i=0;i<12;i++)
{
if (i == 0)
{
PdfPCell cell = new PdfPCell();
cell.setColspan(3);
cell.setBackgroundColor(new Color(180,180,180));
cell.addElement(new Paragraph("表格头" , FontChinese));
table.addCell(cell);
}
else
{
PdfPCell cell = new PdfPCell();
cell.addElement(new Paragraph("表格内容" , FontChinese));
table.addCell(cell);
}
}
document.add(table);
}
catch (DocumentException de)
{
System.err.println(de.getMessage());
}
catch (IOException ioe)
{
System.err.println(ioe.getMessage());
}
//关闭document
document.close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -