所用java包iText-2.1.2.jar,iTextAsian-1.0.jar点击(此处)折叠或打开点击(此处)折叠或打开 package atest;import java.awt.Color;import java.io.FileNotFoundException;import java.io.FileOutputStream;import com.lowagie.text.Document;import com.lowagie.text.DocumentException;import com.lowagie.text.Font;import com.lowagie.text.Paragraph;import com.lowagie.text.pdf.PdfWriter;public class itexttest { /** * [メソッドの説明を書きましょう] * @param args */ public static void main(String[] args) { try { //1.创建一个document Document document = new Document(); //2.定义pdfWriter,指明文件输出流输出到一个文件 PdfWriter.getInstance(document,new FileOutputStream("D:itexttest.pdf")); //3.打开文档 document.open(); //字体 Font font = new Font(); font.setFamily("STSongStd-Light"); //颜色 //font.setColor(BaseColor.BLUE); font.setColor(Color.BLUE); //4.添加内容 Paragraph content = new Paragraph("xxx!",font); document.add(content); //添加段落 for(int i=0;i<100;i++){ document.add(new Paragraph(i+1 + ":HelloWorld"+","+"Hello iText"+","+"Hello Hiya Chen")); } //5.关闭 document.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }} package atest;import java.awt.Color;import java.io.FileNotFoundException;import java.io.FileOutputStream;import com.lowagie.text.Document;import com.lowagie.text.DocumentException;import com.lowagie.text.Font;import com.lowagie.text.Paragraph;import com.lowagie.text.pdf.PdfWriter;public class itexttest { /** * [メソッドの説明を書きましょう] * @param args */ public static void main(String[] args) { try { //1.创建一个document Document document = new Document(); //2.定义pdfWriter,指明文件输出流输出到一个文件 PdfWriter.getInstance(document,new FileOutputStream("D:itexttest.pdf")); //3.打开文档 document.open(); //字体 Font font = new Font(); font.setFamily("STSongStd-Light"); //颜色 //font.setColor(BaseColor.BLUE); font.setColor(Color.BLUE); //4.添加内容 Paragraph content = new Paragraph("xxx!",font); document.add(content); //添加段落 for(int i=0;i<100;i++){ document.add(new Paragraph(i+1 + ":HelloWorld"+","+"Hello iText"+","+"Hello Hiya Chen")); } //5.关闭 document.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (DocumentException e) { e.printStackTrace(); } }}
阅读(1329) | 评论(0) | 转发(0) |