Java: Configurer la couleur de fond d’un document PDF

Author:

Java: Configurer la couleur de fond d'un document PDF
{filelink=10505}

/***** Code de MesExemples.com *******/
/**
 * @(#)UpdateBackgroundColorPDF.java
 *
 *
 * @author 
 *sakoba(java.mesexemples.com) @version 1.00 2013/5/29
 */

import java.io.FileOutputStream;
import java.io.IOException;

import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.Rectangle;
import com.itextpdf.text.pdf.PdfWriter;

public class UpdateBackgroundColorPDF {
  public static void main(String[] args) {
    Rectangle pageSize = new Rectangle(216, 720);
    // Modifier la couleur de fond
    pageSize.setBackgroundColor(new com.itextpdf.text.BaseColor(0xFF, 0xFF, 
    0xDE));
    Document document = new Document(pageSize);
    
    try {
      PdfWriter.getInstance(document, 
      	new FileOutputStream("c:/UpdateBackgroundColorPDF.pdf"));
      document.open();
      document.add(new Paragraph("Text"));

    } catch (DocumentException de) {
      System.err.println(de.getMessage());
    } catch (IOException ioe) {
      System.err.println(ioe.getMessage());
    }
    document.close();
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *