java使用itext生成pdf文件:设置pdf背景示例,itextpdf,设置背景需要首先建立Re
分享于 点击 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(); }}
用户点评