public class TextColumnCollection
Use To make all columns equal width and spaced evenly, set If you have EvenlySpaced set to false, you need to specify width and spacing for each
column individually. Use the indexer to access individual When using custom column widths, make sure the sum of all column widths and spacings between them
equals page width minus left and right page margins. Example:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
TextColumnCollection columns = builder.getPageSetup().getTextColumns();
columns.setSpacing(100.0);
columns.setCount(2);
builder.writeln("Column 1.");
builder.insertBreak(BreakType.COLUMN_BREAK);
builder.writeln("Column 2.");
doc.save(getArtifactsDir() + "PageSetup.ColumnsSameWidth.docx");
Property Getters/Setters Summary | ||
---|---|---|
int | getCount() | |
Gets the number of columns in the section of a document.
|
||
boolean | getEvenlySpaced() | |
void | setEvenlySpaced(booleanvalue) | |
True if text columns are of equal width and evenly spaced. | ||
boolean | getLineBetween() | |
void | setLineBetween(booleanvalue) | |
When true, adds a vertical line between columns. | ||
double | getSpacing() | |
void | setSpacing(doublevalue) | |
When columns are evenly spaced, gets or sets the amount of space between each column in points. | ||
double | getWidth() | |
When columns are evenly spaced, gets the width of the columns.
|
||
TextColumn | get(int index) | |
Returns a text column at the specified index.
|
Method Summary | ||
---|---|---|
void | setCount(int newCount) | |
Arranges text into the specified number of text columns.
|
public int getCount()
public boolean getEvenlySpaced() / public void setEvenlySpaced(boolean value)
Example:
Shows how to create unevenly spaced columns.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); PageSetup pageSetup = builder.getPageSetup(); TextColumnCollection columns = pageSetup.getTextColumns(); columns.setEvenlySpaced(false); columns.setCount(2); // Determine the amount of room that we have available for arranging columns. double contentWidth = pageSetup.getPageWidth() - pageSetup.getLeftMargin() - pageSetup.getRightMargin(); Assert.assertEquals(468.0d, contentWidth, 0.01d); // Set the first column to be narrow. TextColumn column = columns.get(0); column.setWidth(100.0); column.setSpaceAfter(20.0); // Set the second column to take the rest of the space available within the margins of the page. column = columns.get(1); column.setWidth(contentWidth - column.getWidth() - column.getSpaceAfter()); builder.writeln("Narrow column 1."); builder.insertBreak(BreakType.COLUMN_BREAK); builder.writeln("Wide column 2."); doc.save(getArtifactsDir() + "PageSetup.CustomColumnWidth.docx");
public boolean getLineBetween() / public void setLineBetween(boolean value)
Example:
Shows how to separate columns with a vertical line.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); // Configure the current section's PageSetup object to divide the text into several columns. // Set the "LineBetween" property to "true" to put a dividing line between columns. // Set the "LineBetween" property to "false" to leave the space between columns blank. TextColumnCollection columns = builder.getPageSetup().getTextColumns(); columns.setLineBetween(lineBetween); columns.setCount(3); builder.writeln("Column 1."); builder.insertBreak(BreakType.COLUMN_BREAK); builder.writeln("Column 2."); builder.insertBreak(BreakType.COLUMN_BREAK); builder.writeln("Column 3."); doc.save(getArtifactsDir() + "PageSetup.VerticalLineBetweenColumns.docx");
public double getSpacing() / public void setSpacing(double value)
Example:
Shows how to create multiple evenly spaced columns in a section.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); TextColumnCollection columns = builder.getPageSetup().getTextColumns(); columns.setSpacing(100.0); columns.setCount(2); builder.writeln("Column 1."); builder.insertBreak(BreakType.COLUMN_BREAK); builder.writeln("Column 2."); doc.save(getArtifactsDir() + "PageSetup.ColumnsSameWidth.docx");
public double getWidth()
Has effect only when
public TextColumn get(int index)
Example:
Shows how to create unevenly spaced columns.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); PageSetup pageSetup = builder.getPageSetup(); TextColumnCollection columns = pageSetup.getTextColumns(); columns.setEvenlySpaced(false); columns.setCount(2); // Determine the amount of room that we have available for arranging columns. double contentWidth = pageSetup.getPageWidth() - pageSetup.getLeftMargin() - pageSetup.getRightMargin(); Assert.assertEquals(468.0d, contentWidth, 0.01d); // Set the first column to be narrow. TextColumn column = columns.get(0); column.setWidth(100.0); column.setSpaceAfter(20.0); // Set the second column to take the rest of the space available within the margins of the page. column = columns.get(1); column.setWidth(contentWidth - column.getWidth() - column.getSpaceAfter()); builder.writeln("Narrow column 1."); builder.insertBreak(BreakType.COLUMN_BREAK); builder.writeln("Wide column 2."); doc.save(getArtifactsDir() + "PageSetup.CustomColumnWidth.docx");
public void setCount(int newCount)
When
newCount
- The number of columns the text is to be arranged into.Example:
Shows how to create multiple evenly spaced columns in a section.Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); TextColumnCollection columns = builder.getPageSetup().getTextColumns(); columns.setSpacing(100.0); columns.setCount(2); builder.writeln("Column 1."); builder.insertBreak(BreakType.COLUMN_BREAK); builder.writeln("Column 2."); doc.save(getArtifactsDir() + "PageSetup.ColumnsSameWidth.docx");