com.aspose.words
Class ControlChar

java.lang.Object
    extended by com.aspose.words.ControlChar

public abstract class ControlChar 
extends java.lang.Object

Utility class containing constants. Control characters often encountered in documents. Provides both char and string versions of the same constants. For example: string ControlChar.LineBreak and char ControlChar.LineBreakChar have the same value.

Example:

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!");

// The entire document, when in string form, will display some structural features such as breaks with control characters
Assert.assertEquals(MessageFormat.format("Hello world!{0}Hello again!{1}{2}", ControlChar.CR, ControlChar.CR, ControlChar.PAGE_BREAK), doc.getText());

// Some of them can be trimmed out
Assert.assertEquals(MessageFormat.format("Hello world!{0}Hello again!", ControlChar.CR), doc.getText().trim());

Field Summary
static final java.lang.StringCELL
           End of a table cell or end of a table row character: "\x0007" or "\a".
static final java.lang.StringTAB
           Tab character: "\x0009" or "\t".
static final java.lang.StringLF
           Line feed character: "\x000a" or "\n". Same as LINE_FEED.
static final java.lang.StringLINE_FEED
           Line feed character: "\x000a" or "\n". Same as LF.
static final java.lang.StringLINE_BREAK
           Line break character: "\x000b" or "\v".
static final java.lang.StringPAGE_BREAK
           Page break character: "\x000c" or "\f". Note it has the same value as SECTION_BREAK.
static final java.lang.StringSECTION_BREAK
           End of section character: "\x000c" or "\f". Note it has the same value as PAGE_BREAK.
static final java.lang.StringCR
           Carriage return character: "\x000d" or "\r". Same as PARAGRAPH_BREAK.
static final java.lang.StringPARAGRAPH_BREAK
           End of paragraph character: "\x000d" or "\r". Same as CR
static final java.lang.StringCOLUMN_BREAK
           End of column character: "\x000e".
static final java.lang.StringCR_LF
           Carriage return followed by line feed character: "\x000d\x000a" or "\r\n". Not used as such in Microsoft Word documents, but commonly used in text files for paragraph breaks.
static final java.lang.StringNON_BREAKING_SPACE
           Non-breaking space character: "\x00a0".
static final charCELL_CHAR
           End of a table cell or end of a table row character: (char)7 or "\a".
static final charTAB_CHAR
           Tab character: (char)9 or "\t".
static final charLINE_FEED_CHAR
           Line feed character: (char)10 or "\n".
static final charLINE_BREAK_CHAR
           Line break character: (char)11 or "\v".
static final charPAGE_BREAK_CHAR
           Page break character: (char)12 or "\f".
static final charSECTION_BREAK_CHAR
           End of section character: (char)12 or "\f".
static final charPARAGRAPH_BREAK_CHAR
           End of paragraph character: (char)13 or "\r".
static final charCOLUMN_BREAK_CHAR
           End of column character: (char)14.
static final charFIELD_START_CHAR
           Start of MS Word field character: (char)19.
static final charFIELD_SEPARATOR_CHAR
           Field separator character separates field code from field value. Optional in some fields. Value: (char)20.
static final charFIELD_END_CHAR
           End of MS Word field character: (char)21.
static final charNON_BREAKING_HYPHEN_CHAR
           Nonbreaking Hyphen in Microsoft Word is (char)30.
static final charOPTIONAL_HYPHEN_CHAR
           Optional Hyphen in Microsoft Word is (char)31.
static final charSPACE_CHAR
           Space character: (char)32.
static final charNON_BREAKING_SPACE_CHAR
           Non-breaking space character: (char)160.
static final charDEFAULT_TEXT_INPUT_CHAR
           This is the "o" character used as a default value in text input form fields.
 

Field Detail

CELL

public static final java.lang.String CELL
End of a table cell or end of a table row character: "\x0007" or "\a".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

TAB

public static final java.lang.String TAB
Tab character: "\x0009" or "\t".

Example:

Shows how to change default tab positions for the document and inserts text with some tab characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set default tab stop to 72 points (1 inch)
builder.getDocument().setDefaultTabStop(72.0);

builder.writeln("Hello" + ControlChar.TAB + "World!");
builder.writeln("Hello" + ControlChar.TAB_CHAR + "World!");

LF

public static final java.lang.String LF
Line feed character: "\x000a" or "\n". Same as LINE_FEED.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

LINE_FEED

public static final java.lang.String LINE_FEED
Line feed character: "\x000a" or "\n". Same as LF.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

LINE_BREAK

public static final java.lang.String LINE_BREAK
Line break character: "\x000b" or "\v".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

PAGE_BREAK

public static final java.lang.String PAGE_BREAK
Page break character: "\x000c" or "\f". Note it has the same value as SECTION_BREAK.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

SECTION_BREAK

public static final java.lang.String SECTION_BREAK
End of section character: "\x000c" or "\f". Note it has the same value as PAGE_BREAK.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

CR

public static final java.lang.String CR
Carriage return character: "\x000d" or "\r". Same as PARAGRAPH_BREAK.

Example:

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!");

// The entire document, when in string form, will display some structural features such as breaks with control characters
Assert.assertEquals(MessageFormat.format("Hello world!{0}Hello again!{1}{2}", ControlChar.CR, ControlChar.CR, ControlChar.PAGE_BREAK), doc.getText());

// Some of them can be trimmed out
Assert.assertEquals(MessageFormat.format("Hello world!{0}Hello again!", ControlChar.CR), doc.getText().trim());

PARAGRAPH_BREAK

public static final java.lang.String PARAGRAPH_BREAK
End of paragraph character: "\x000d" or "\r". Same as CR

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

COLUMN_BREAK

public static final java.lang.String COLUMN_BREAK
End of column character: "\x000e".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

CR_LF

public static final java.lang.String CR_LF
Carriage return followed by line feed character: "\x000d\x000a" or "\r\n". Not used as such in Microsoft Word documents, but commonly used in text files for paragraph breaks.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

NON_BREAKING_SPACE

public static final java.lang.String NON_BREAKING_SPACE
Non-breaking space character: "\x00a0".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

CELL_CHAR

public static final char CELL_CHAR
End of a table cell or end of a table row character: (char)7 or "\a".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

TAB_CHAR

public static final char TAB_CHAR
Tab character: (char)9 or "\t".

Example:

Shows how to change default tab positions for the document and inserts text with some tab characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Set default tab stop to 72 points (1 inch)
builder.getDocument().setDefaultTabStop(72.0);

builder.writeln("Hello" + ControlChar.TAB + "World!");
builder.writeln("Hello" + ControlChar.TAB_CHAR + "World!");

LINE_FEED_CHAR

public static final char LINE_FEED_CHAR
Line feed character: (char)10 or "\n".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

LINE_BREAK_CHAR

public static final char LINE_BREAK_CHAR
Line break character: (char)11 or "\v".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

PAGE_BREAK_CHAR

public static final char PAGE_BREAK_CHAR
Page break character: (char)12 or "\f".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

SECTION_BREAK_CHAR

public static final char SECTION_BREAK_CHAR
End of section character: (char)12 or "\f".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

PARAGRAPH_BREAK_CHAR

public static final char PARAGRAPH_BREAK_CHAR
End of paragraph character: (char)13 or "\r".

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

COLUMN_BREAK_CHAR

public static final char COLUMN_BREAK_CHAR
End of column character: (char)14.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

FIELD_START_CHAR

public static final char FIELD_START_CHAR
Start of MS Word field character: (char)19.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

FIELD_SEPARATOR_CHAR

public static final char FIELD_SEPARATOR_CHAR
Field separator character separates field code from field value. Optional in some fields. Value: (char)20.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

FIELD_END_CHAR

public static final char FIELD_END_CHAR
End of MS Word field character: (char)21.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

NON_BREAKING_HYPHEN_CHAR

public static final char NON_BREAKING_HYPHEN_CHAR
Nonbreaking Hyphen in Microsoft Word is (char)30.

Nonbreaking 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.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

OPTIONAL_HYPHEN_CHAR

public static final char OPTIONAL_HYPHEN_CHAR
Optional Hyphen in Microsoft Word is (char)31.

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.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

SPACE_CHAR

public static final char SPACE_CHAR
Space character: (char)32.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

NON_BREAKING_SPACE_CHAR

public static final char NON_BREAKING_SPACE_CHAR
Non-breaking space character: (char)160.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

DEFAULT_TEXT_INPUT_CHAR

public static final char DEFAULT_TEXT_INPUT_CHAR
This is the "o" character used as a default value in text input form fields.

Example:

Shows how to use various control characters.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

// Add a regular space
builder.write("Before space." + ControlChar.SPACE_CHAR + "After space.");

// Add a NBSP, or non-breaking space
// Unlike the regular space, this space can't 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.");

// This adds a new line and starts a new paragraph
// Same value as ControlChar.Lf
Assert.assertEquals(doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount(), 1);
builder.write("Before line feed." + ControlChar.LINE_FEED + "After line feed.");
Assert.assertEquals(2, doc.getFirstSection().getBody().getChildNodes(NodeType.PARAGRAPH, true).getCount());

// Carriage returns and line feeds can be represented together by one character
Assert.assertEquals(ControlChar.CR_LF, ControlChar.CR + ControlChar.LF);

// The line feed character has two versions
Assert.assertEquals(ControlChar.LINE_FEED, ControlChar.LF);

// Add a paragraph break, also adding 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. Note that 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);

// A page break is the same value as a section break
builder.write("Before page break." + ControlChar.PAGE_BREAK + "After page break.");

// We can add a new section like this
doc.appendChild(new Section(doc));
builder.moveToSection(1);

// If you have a section with more than one column, you can use a column break to make following text start on a new column
builder.getCurrentSection().getPageSetup().getTextColumns().setCount(2);
builder.write("Text at end of column 1." + ControlChar.COLUMN_BREAK + "Text at beginning of column 2.");

// Save document to see the characters we added
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);

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.