import java.io.FileOutputStream;
import com.lowagie.text.Document;
import com.lowagie.text.Element;
import com.lowagie.text.PageSize;
import com.lowagie.text.Phrase;
import com.lowagie.text.pdf.ColumnText;
import com.lowagie.text.pdf.PdfContentByte;
import com.lowagie.text.pdf.PdfWriter;
public class MainClass {
public static void main(String[] args) throws Exception {
Document document = new Document(PageSize.A4);
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
document.open();
PdfContentByte cb = writer.getDirectContent();
ColumnText ct = new ColumnText(cb);
ct.setAlignment(Element.ALIGN_JUSTIFIED);
ct.setExtraParagraphSpace(12);
ct.setFollowingIndent(18);
ct.setLeading(0, 1.2f);
ct.setSpaceCharRatio(PdfWriter.NO_SPACE_CHAR_RATIO);
ct.setUseAscender(true);
Phrase p;
ct.setSimpleColumn(36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36);
for (int i = 0; i < 10; i++) {
p = new Phrase(i + "\n");
ct.addText(p);
}
int status = ColumnText.START_COLUMN;
while (ColumnText.hasMoreText(status)) {
status = ct.go();
ct.setYLine(PageSize.A4.height() - 36);
document.newPage();
}
document.close();
}
}
|