public class ControlChar
extends java.lang.Object
To learn more, visit the Working With Control Characters documentation article.
Remarks:
Provides both char and string versions of the same constants. For example: string LINE_BREAK and char LINE_BREAK_CHAR have the same value.
Examples:
Shows how to use control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert paragraphs with text with DocumentBuilder.
builder.writeln("Hello world!");
builder.writeln("Hello again!");
// Converting the document to text form reveals that control characters
// represent some of the document's structural elements, such as page breaks.
Assert.assertEquals(MessageFormat.format("Hello world!{0}", ControlChar.CR) +
MessageFormat.format("Hello again!{0}", ControlChar.CR) +
ControlChar.PAGE_BREAK, doc.getText());
// When converting a document to string form,
// we can omit some of the control characters with the Trim method.
Assert.assertEquals(MessageFormat.format("Hello world!{0}", ControlChar.CR) +
"Hello again!", doc.getText().trim());
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CELL
End of a table cell or end of a table row character: "\x0007" or "\a".
|
static char |
CELL_CHAR
End of a table cell or end of a table row character: (char)7 or "\a".
|
static java.lang.String |
COLUMN_BREAK
End of column character: "\x000e".
|
static char |
COLUMN_BREAK_CHAR
End of column character: (char)14.
|
static java.lang.String |
CR
Carriage return character: "\x000d" or "\r".
|
static java.lang.String |
CR_LF
Carriage return followed by line feed character: "\x000d\x000a" or "\r\n".
|
static char |
DEFAULT_TEXT_INPUT_CHAR
This is the "o" character used as a default value in text input form fields.
|
static char |
FIELD_END_CHAR
End of MS Word field character: (char)21.
|
static char |
FIELD_SEPARATOR_CHAR
Field separator character separates field code from field value.
|
static char |
FIELD_START_CHAR
Start of MS Word field character: (char)19.
|
static java.lang.String |
LF
Line feed character: "\x000a" or "\n".
|
static java.lang.String |
LINE_BREAK
Line break character: "\x000b" or "\v".
|
static char |
LINE_BREAK_CHAR
Line break character: (char)11 or "\v".
|
static java.lang.String |
LINE_FEED
Line feed character: "\x000a" or "\n".
|
static char |
LINE_FEED_CHAR
Line feed character: (char)10 or "\n".
|
static char |
NON_BREAKING_HYPHEN_CHAR
Non-breaking Hyphen in Microsoft Word is (char)30.
|
static java.lang.String |
NON_BREAKING_SPACE
Non-breaking space character: "\x00a0".
|
static char |
NON_BREAKING_SPACE_CHAR
Non-breaking space character: (char)160.
|
static char |
OPTIONAL_HYPHEN_CHAR
Optional Hyphen in Microsoft Word is (char)31.
|
static java.lang.String |
PAGE_BREAK
Page break character: "\x000c" or "\f".
|
static char |
PAGE_BREAK_CHAR
Page break character: (char)12 or "\f".
|
static java.lang.String |
PARAGRAPH_BREAK
End of paragraph character: "\x000d" or "\r".
|
static char |
PARAGRAPH_BREAK_CHAR
End of paragraph character: (char)13 or "\r".
|
static java.lang.String |
SECTION_BREAK
End of section character: "\x000c" or "\f".
|
static char |
SECTION_BREAK_CHAR
End of section character: (char)12 or "\f".
|
static char |
SPACE_CHAR
Space character: (char)32.
|
static java.lang.String |
TAB
Tab character: "\x0009" or "\t".
|
static char |
TAB_CHAR
Tab character: (char)9 or "\t".
|
public static char CELL_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char TAB_CHAR
Examples:
Shows how to set a custom interval for tab stop positions.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set tab stops to appear every 72 points (1 inch).
builder.getDocument().setDefaultTabStop(72.0);
// Each tab character snaps the text after it to the next closest tab stop position.
builder.writeln("Hello" + ControlChar.TAB + "World!");
builder.writeln("Hello" + ControlChar.TAB_CHAR + "World!");
public static char LINE_FEED_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char LINE_BREAK_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char PAGE_BREAK_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char SECTION_BREAK_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char PARAGRAPH_BREAK_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char COLUMN_BREAK_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char FIELD_START_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char FIELD_SEPARATOR_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char FIELD_END_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char NON_BREAKING_HYPHEN_CHAR
Remarks:
Non-breaking Hyphen in Microsoft Word does not correspond to the Unicode character U+2011 non-breaking hyphen but instead represents internal information that tells Microsoft Word to display a hyphen and not to break a line.
Useful info: http://www.cs.tut.fi/~jkorpela/dashes.html#linebreaks.
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char OPTIONAL_HYPHEN_CHAR
Remarks:
Optional Hyphen in Microsoft Word does not correspond to the Unicode character U+00AD soft hyphen. Instead, it inserts internal information that tells Word about a possible hyphenation point.
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char SPACE_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char NON_BREAKING_SPACE_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static char DEFAULT_TEXT_INPUT_CHAR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String CELL
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String TAB
Examples:
Shows how to set a custom interval for tab stop positions.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Set tab stops to appear every 72 points (1 inch).
builder.getDocument().setDefaultTabStop(72.0);
// Each tab character snaps the text after it to the next closest tab stop position.
builder.writeln("Hello" + ControlChar.TAB + "World!");
builder.writeln("Hello" + ControlChar.TAB_CHAR + "World!");
public static java.lang.String LF
LINE_FEED.
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String LINE_FEED
LF.
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String LINE_BREAK
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String PAGE_BREAK
SECTION_BREAK.
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String SECTION_BREAK
PAGE_BREAK.
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String CR
PARAGRAPH_BREAK.
Examples:
Shows how to use control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Insert paragraphs with text with DocumentBuilder.
builder.writeln("Hello world!");
builder.writeln("Hello again!");
// Converting the document to text form reveals that control characters
// represent some of the document's structural elements, such as page breaks.
Assert.assertEquals(MessageFormat.format("Hello world!{0}", ControlChar.CR) +
MessageFormat.format("Hello again!{0}", ControlChar.CR) +
ControlChar.PAGE_BREAK, doc.getText());
// When converting a document to string form,
// we can omit some of the control characters with the Trim method.
Assert.assertEquals(MessageFormat.format("Hello world!{0}", ControlChar.CR) +
"Hello again!", doc.getText().trim());
public static java.lang.String PARAGRAPH_BREAK
CR
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String COLUMN_BREAK
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String CR_LF
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);
public static java.lang.String NON_BREAKING_SPACE
Examples:
Shows how to add various control characters to a document.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
// Add a regular space.
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");
// Add an NBSP, which is a non-breaking space.
// Unlike the regular space, this space cannot have an automatic line break at its position.
builder.write("Before space." + ControlChar.NON_BREAKING_SPACE + "After space.");
// Add a tab character.
builder.write("Before tab." + ControlChar.TAB + "After tab.");
// Add a line break.
builder.write("Before line break." + ControlChar.LINE_BREAK + "After line break.");
// Add a new line and starts a new paragraph.
Assert.assertEquals(1, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());
// The line feed character has two versions.
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);
// Carriage returns and line feeds can be represented together by one character.
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);
// Add a paragraph break, which will start a new paragraph.
builder.write("Before paragraph break." + ControlChar.PARAGRAPH_BREAK + "After paragraph break.");
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 3);
// Add a section break. This does not make a new section or paragraph.
Assert.assertEquals(doc.getSections().getCount(), 1);
builder.write("Before section break." + ControlChar.SECTION_BREAK + "After section break.");
Assert.assertEquals(doc.getSections().getCount(), 1);
// Add a page break.
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");
// A page break is the same value as a section break.
Assert.assertEquals(ControlChar.PAGE_BREAK, ControlChar.SECTION_BREAK);
// Insert a new section, and then set its column count to two.
doc.appendChild(new Section(doc));
builder.moveToSection(1);
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
// We can use a control character to mark the point where text moves to the next column.
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");
doc.save(getArtifactsDir() + "ControlChar.InsertControlChars.docx");
// There are char and string counterparts for most characters.
Assert.assertEquals(ControlChar.CELL.toCharArray()[0], ControlChar.CELL_CHAR);
Assert.assertEquals(ControlChar.NON_BREAKING_SPACE.toCharArray()[0], ControlChar.NON_BREAKING_SPACE_CHAR);
Assert.assertEquals(ControlChar.TAB.toCharArray()[0], ControlChar.TAB_CHAR);
Assert.assertEquals(ControlChar.LINE_BREAK.toCharArray()[0], ControlChar.LINE_BREAK_CHAR);
Assert.assertEquals(ControlChar.LINE_FEED.toCharArray()[0], ControlChar.LINE_FEED_CHAR);
Assert.assertEquals(ControlChar.PARAGRAPH_BREAK.toCharArray()[0], ControlChar.PARAGRAPH_BREAK_CHAR);
Assert.assertEquals(ControlChar.SECTION_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.PAGE_BREAK.toCharArray()[0], ControlChar.SECTION_BREAK_CHAR);
Assert.assertEquals(ControlChar.COLUMN_BREAK.toCharArray()[0], ControlChar.COLUMN_BREAK_CHAR);