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

Custom Page Margins 

iText is a free and open source library for creating and manipulating PDF documents in Java. The following example shows using custom page margins in PDF document.

File Name  :  
com/bethecoder/tutorials/itext/tests/CustomPageMarginExample.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.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class CustomPageMarginExample {

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

    float marginLeft = 0
    float marginRight = 0;
    float marginTop = 20;
    float marginBottom = 0;
    
    Document document = new Document(
        PageSize.A6, marginLeft, marginRight, marginTop, marginBottom)
    PdfWriter.getInstance(document, new FileOutputStream("test25.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,
test25.jpg


 
  


  
bl  br