tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 PDF > iTEXT > Document Border

Document Border 

iText is a free and open source library for creating and manipulating PDF documents in Java. The following example shows setting document border of a PDF document.

File Name  :  
com/bethecoder/tutorials/itext/tests/BorderTests.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.itext.tests;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;

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

public class BorderTests {

  /**
   @param args
   @throws DocumentException 
   @throws FileNotFoundException 
   */
  public static void main(String[] argsthrows FileNotFoundException, DocumentException {

    //Create layout and set background & borders
    Rectangle layout = new Rectangle(PageSize.A4);
    layout.setBackgroundColor(new BaseColor(100200180))//Background color
    layout.setBorderColor(BaseColor.DARK_GRAY);  //Border color
    layout.setBorderWidth(6);      //Border width  
    layout.setBorder(Rectangle.BOX);  //Border on 4 sides
    
    Document document = new Document(layout)
    PdfWriter.getInstance(document, new FileOutputStream("test8.pdf"));
    
    //Open the document before adding any content
    document.open();
    
    Paragraph paragraph = new Paragraph("BE THE CODER");
    document.add(paragraph);
    
    //Close the document
    document.close();
  }

}
   

It gives the following output,
test8.jpg


 
  


  
bl  br