Mega Code Archive

 
Categories / Java Tutorial / PDF
 

Custom margins

The left margin of  this document is 36pt (0.5 inch);  the right margin 72pt (1 inch);  the top margin 108pt (1.5 inch);  the bottom margin 180pt (2.5 inch). import java.io.FileOutputStream; import com.lowagie.text.Document; import com.lowagie.text.Element; import com.lowagie.text.PageSize; import com.lowagie.text.Paragraph; import com.lowagie.text.pdf.PdfWriter; public class MainClass {   public static void main(String[] args) throws Exception {     Document document = new Document(PageSize.A5, 36, 72, 108, 180);     PdfWriter.getInstance(document, new FileOutputStream("1.pdf"));     document.open();     document.add(new Paragraph("this is a test"));     Paragraph paragraph = new Paragraph();     paragraph.setAlignment(Element.ALIGN_JUSTIFIED);     for (int i = 0; i < 20; i++) {       paragraph.add("Hello People. ");     }     document.add(paragraph);     document.close();   } }