欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java使用itext生成pdf文件:设置pdf背景示例,itextpdf,设置背景需要首先建立Re

来源: javaer 分享于  点击 45086 次 点评:241

java使用itext生成pdf文件:设置pdf背景示例,itextpdf,设置背景需要首先建立Re


设置背景需要首先建立Rectangle对象,并指定其大小范围,然后通过其setBackgroundColor(Color)方法即可设置pdf的背景。

import java.io.*;import com.lowagie.text.*;import com.lowagie.text.pdf.*;public class backgroundColorPDF{         public static void main(String arg[])throws Exception    {                           Rectangle pageSize = new Rectangle(400, 400);        pageSize.setBackgroundColor            (new java.awt.Color(0xDF, 0xFF, 0xDE));        Document document = new Document(pageSize);        PdfWriter.getInstance(document,            new FileOutputStream("backgroundColorPDF.pdf"));        document.open();        Paragraph para=new Paragraph("Page Size and Background color");        document.add(para);        document.add(new Paragraph("Background color--->>roseinia.net"));        document.close();    }}
相关栏目:

用户点评