Java Tutorial/PDF/Background Color

Материал из Java эксперт
Перейти к: навигация, поиск

Set backgroundcolor to cornflower blue

import java.awt.Color;
import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Paragraph;
import com.lowagie.text.Rectangle;
import com.lowagie.text.pdf.PdfWriter;

public class SetBackgroundColorBlue {
   public static void main(String[] args) throws Exception{
        Rectangle pagesize = new Rectangle(612, 792);
        pagesize.setBackgroundColor(new Color(0x64, 0x95, 0xed));
        Document document = new Document(pagesize);
        try {
            PdfWriter.getInstance(
                    document,
                    new FileOutputStream("HelloWorldBlue.pdf"));
            document.open();
            document.add(new Paragraph("Hello World"));
        document.close();
    }
}