⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 helloaccp.java

📁 主题:用iText输出PDF报表 内容组织: 1. 自我介绍 2. 简要介绍报表是什么 3. 为什么要输出PDF
💻 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 + -