Java Programing laungage

iText Projects

iText Project 1

adplus-dvertising
Set the PDF Page margin
Previous Home Next

By the help of this program we can create the PDF page which left the margin in the PDF file. For creating Margin page we firstly create the PDF file by utilizing the two package, which is help to create the PDF file and manipulation in it. These package are

  • java.io.*;
  • com.lowagie.text.pdf.*; and
  • com.lowagie.text.*;

For doing this, firstly import the some package. Before this we are going to add the iText jar file in our project. then we can start the code.

Example

package r4r;
import java.io.*;
import com.lowagie.text.Document;
import com.lowagie.text.PageSize;
import com.lowagie.text.Paragraph;
import com.lowagie.text.pdf.PdfWriter;

public class marginetest 
	{
public static void main(String[] arg)throws Exception
	{
Paragraph paragraph=new Paragraph(); 
Document doc = new Document(PageSize.A4, 36, 72, 108, 180);
PdfWriter.getInstance(doc,new FileOutputStream
("marginetest.pdf"));

doc.open(); 
doc.add(new Paragraph(
"Margin Test"));

doc.setMargins(100,100,100,100);
doc.add(new Paragraph
("This is the R4R tutorials Visit it Please"));

for (int k = 0; k < 20; k++) { 
paragraph.add
("Welcome friends in the R4R Tutotrials\n");

}
doc.setMarginMirroring(true);
doc.add(new Paragraph("Done"));
doc.add(paragraph);
doc.close();
}
}
Previous Home Next