frank oo java

我爱oo,我爱java。http://oofrank.blogchina.com

My Links

Blog统计

公告

欢迎到 oofrank@blogchina 来 QQ:421057986 email:oofrank@163.com
www.flickr.com
oofrank@flickr with my S9500

Free Download Manager
Free Download Manager

文章

收藏

相册

IT

other

存档


正在读取评论……

1、使用iTextAsian.jar中的字体
    BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
2、使用Windows系统字体(TrueType)
        BaseFont.createFont("C:/WINDOWS/Fonts/SIMYOU.TTF", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);    
3、使用资源字体(ClassPath)
    BaseFont.createFont("/SIMYOU.TTF", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);   

示例代码:
    ByteArrayOutputStream baos = new ByteArrayOutputStream(OUTPUT_BYTE_ARRAY_INITIAL_SIZE);
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, baos);
    writer.setViewerPreferences(PdfWriter.AllowPrinting  | PdfWriter.PageLayoutSinglePage);
    BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);
    Font font = new Font(bf, 12, Font.NORMAL);
    document.open();
    Paragraph p = new Paragraph("你好", font);
    document.add(p);
    document.add(new Paragraph("Test2"));
    Table table = new Table(2, 3);
    table.addCell(new Phrase("我好", font));
    table.addCell("C2R1");
    table.addCell("C1R2");
    table.addCell("C2R2");
    Cell c = (Cell) table.getElement(0, 0);
    c.setVerticalAlignment("Middle");
    c.setBackgroundColor(new Color(255, 0, 0));
    c.setHorizontalAlignment("Center");
    document.add(table);
    document.close();
    baos.writeTo(new FileOutputStream("F:\\test.pdf"));    


Trackback: http://tb.donews.net/TrackBack.aspx?PostId=851650


[点击此处收藏本文]  发表于2006年04月30日 9:10 AM




正在读取评论……
大名
网址
验证码
评论