This example shows you how to change the page format to have no margins, allowing to write at the top and bottom of the PDF page.

To change the page format, you have to use the Paper and PageFormat classes:

Paper p = new Paper ();
// this is standard letter size
p.setSize(8.5 * 72, 11 * 72);
p.setImageableArea(0, 0, 8.5 * 72, 11 * 72);
 
PageFormat pf = new PageFormat ();
pf.setPaper(p);

It is important to set all the paper properties first, because after making the call to PageFormat.setPaper(p), this creates a copy of the Paper object and any calls you make after that on the Paper object will have no effect.

Here is a sample program using free jPDFWriter creating a new PDF document, adding a letter size page to the document and saving the document.

// create PDF document
PDFDocument pdfDoc = new PDFDocument ();
 
// create a PageFormat of standard letter size 
// with no margins
Paper p = new Paper ();
p.setSize(8.5 * 72, 11 * 72);
p.setImageableArea(0, 0, 8.5 * 72, 11 * 72);
PageFormat pf = new PageFormat ();
pf.setPaper(p);
 
// create a new page and add it to the PDF (important!)
PDFPage page = pdfDoc.createPage(pf);
pdfDoc.addPage(page); 
 
// Save the document
 pdfDoc.saveDocument ("C:\\output.pdf");