安卓JAVA將table導出成PDF

来源:互联网 发布:手机掌上贵金属软件 编辑:程序博客网 时间:2024/05/19 01:10

將table導出成PDF是常見的需求,使用itextpdf導出會非常簡單


import java.io.FileOutputStream;import com.itextpdf.text.Document;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 DrawPdf {  public static void main(String[] args) throws Exception {    Document document = new Document();    PdfWriter.getInstance(document, new FileOutputStream("Employee.pdf"));    document.open();        Paragraph para = new Paragraph("adidas originals");    para.setSpacingAfter(20);    document.add(para);        PdfPTable table = new PdfPTable(3);    PdfPCell cell = new PdfPCell(new Paragraph("First Name"));    table.addCell(cell);    table.addCell("Last Name");    table.addCell("Gender");    table.addCell("Ram");    table.addCell("Kumar");    table.addCell("Male");    table.addCell("Lakshmi");    table.addCell("Devi");    table.addCell("Female");    document.add(table);        document.close();  }}

原创粉丝点击