?? helloaccp.java
字號:
package com.aptech.demo.itext;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.Document;
import com.lowagie.text.DocumentException;
import com.lowagie.text.Font;
import com.lowagie.text.Image;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfPCell;
import com.lowagie.text.pdf.PdfPTable;
import com.lowagie.text.pdf.PdfWriter;
public class HelloACCP {
public static void main(String[] args) throws DocumentException,
IOException {
Rectangle rec = new Rectangle(PageSize.A4);
Document doc = new Document(rec);
PdfWriter.getInstance(doc, new FileOutputStream("HelloACCP.pdf"));
doc.open();
BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",
BaseFont.NOT_EMBEDDED);
Font font = new Font(bf, 12, Font.NORMAL);
Image image = Image.getInstance("mouse.jpg");
image.setAlignment(Image.ALIGN_CENTER);
PdfPTable table = new PdfPTable(2);
float[] widths = new float[]{60, 30};
table.setWidthPercentage(50);
table.setWidths(widths);
table.setHorizontalAlignment(PdfPTable.ALIGN_CENTER);
PdfPCell name = new PdfPCell(new Paragraph("姓名", font));
PdfPCell age = new PdfPCell(new Paragraph("年齡", font));
PdfPCell nameValue = new PdfPCell(new Paragraph("XX", font));
PdfPCell ageValue = new PdfPCell(new Paragraph("18", font));
table.addCell(name);
table.addCell(nameValue);
table.addCell(age);
table.addCell(ageValue);
doc.add(new Paragraph("HelloACCP,你好!", font));
doc.add(image);
doc.add(table);
doc.close();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -