`

Java导出PDF文档

    博客分类:
  • java
阅读更多
package tj;

import java.awt.Color;
import java.io.FileNotFoundException;
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.Paragraph;
import com.lowagie.text.pdf.BaseFont;
import com.lowagie.text.pdf.PdfWriter;

public class JavaToPdf {
	 public static void main(String[] args) {    
         Document doc = null;    
        try {    
             doc = new Document();    
             PdfWriter.getInstance(doc, new FileOutputStream("e:\\itext.pdf"));    
             doc.open();
             BaseFont bfChinese = BaseFont.createFont( "STSongStd-Light" ,  "UniGB-UCS2-H" ,  false );    
             Font fontChinese =  new  Font(bfChinese,  12 , Font.NORMAL, Color.GREEN);
             doc.add(new Paragraph("你好orld",fontChinese));    
         } catch (FileNotFoundException e) {    
             e.printStackTrace();    
         } catch (DocumentException e) {    
             e.printStackTrace();    
         } catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {    
             doc.close();    
         }    
     }    

}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics