Java 类com.lowagie.text.pdf.MultiColumnText 实例源码

项目:itext2    文件:MultiColumnSimpleTest.java   
/**
 * An example using MultiColumnText with irregular columns.
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    OutputStream out = PdfTestBase.getOutputStream("multicolumnsimple.pdf");
    PdfWriter.getInstance(document, out);
    document.open();

    MultiColumnText mct = new MultiColumnText();

    // set up 3 even columns with 10pt space between
    mct.addRegularColumns(document.left(), document.right(), 10f, 3);

    // Write some iText poems
    for (int i = 0; i < 30; i++) {
        mct.addElement(new Paragraph(String.valueOf(i + 1)));
        mct.addElement(newPara(randomWord(noun), Element.ALIGN_CENTER, Font.BOLDITALIC));
        for (int j = 0; j < 4; j++) {
            mct.addElement(newPara(poemLine(), Element.ALIGN_LEFT, Font.NORMAL));
        }
        mct.addElement(newPara(randomWord(adverb), Element.ALIGN_LEFT, Font.NORMAL));
        mct.addElement(newPara("\n\n", Element.ALIGN_LEFT, Font.NORMAL));
    }
    document.add(mct);
    document.close();

}
项目:itext2    文件:MultiColumnR2LTest.java   
/**
 * An example using MultiColumnText with irregular columns.
 */
@Test
public void main() throws Exception {
    Document document = new Document();
    OutputStream out = PdfTestBase.getOutputStream("multicolumnR2L.pdf");
    PdfWriter.getInstance(document, out);
    document.open();

    MultiColumnText mct = new MultiColumnText();
    mct.setColumnsRightToLeft(true);

    // set up 3 even columns with 10pt space between
    mct.addRegularColumns(document.left(), document.right(), 10f, 3);

    // Write some iText poems
    for (int i = 0; i < 30; i++) {
        mct.addElement(new Paragraph(String.valueOf(i + 1)));
        mct.addElement(newPara(randomWord(noun), Element.ALIGN_CENTER, Font.BOLDITALIC));
        for (int j = 0; j < 4; j++) {
            mct.addElement(newPara(poemLine(), Element.ALIGN_LEFT, Font.NORMAL));
        }
        mct.addElement(newPara(randomWord(adverb), Element.ALIGN_LEFT, Font.NORMAL));
        mct.addElement(newPara("\n\n", Element.ALIGN_LEFT, Font.NORMAL));
    }

    document.add(mct);
    document.close();

}