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.setText(new Phrase("string"));
float[] left = { 36, (PageSize.A4.width() / 2) + 18 };
float[] right = { (PageSize.A4.width() / 2) - 18, PageSize.A4.width() - 36 };
int status = ColumnText.START_COLUMN;
int column = 0;
while (ColumnText.hasMoreText(status)) {
ct.setSimpleColumn(left[column], 36, right[column], PageSize.A4.height() - 36);
status = ct.go();
column++;
if (column > 1) {
column = 0;
document.newPage();
}
}
document.close();
}
}
|