{"@attributes":{"version":"2.0"},"channel":{"title":"Documentation \u2013 Programming with Documents in Java","link":"https:\/\/docs.aspose.com\/words\/java\/programming-with-documents\/","description":"Recent content in Programming with Documents in Java on Documentation","generator":"Hugo -- gohugo.io","language":"en","item":[{"title":"Java: Aspose.Words Document Object Model (DOM)","link":"https:\/\/docs.aspose.com\/words\/java\/aspose-words-document-object-model\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/aspose-words-document-object-model\/","description":"\n        \n        \n        <p>The Aspose.Words Document Object Model (DOM) is an in-memory representation of a Word document. The Aspose.Words DOM allows you to programmatically read, manipulate, and modify the content and formatting of a Word document.<\/p>\n<p>This section describes the main classes of the Aspose.Words DOM and their relationships. By using the Aspose.Words DOM classes, you can obtain programmatic access to document elements and formatting.<\/p>\n<h2 id=\"create-a-document-objects-tree\">Create Document Object Tree<\/h2>\n<p>When a document is read into the Aspose.Words DOM, then an object tree is built and different types of elements of the source document have their own DOM tree objects with various properties.<\/p>\n<h3 id=\"build-document-nodes-tree\">Build Document Nodes Tree<\/h3>\n<p>When Aspose.Words reads a Word document into memory, it creates objects of different types that represent various document elements. Every run of a text, paragraph, table, or section is a node, and even the document itself is a node. Aspose.Words defines a class for every document node type.<\/p>\n<p>The document tree in Aspose.Words follows the Composite Design Pattern:<\/p>\n<ul>\n<li>All node classes ultimately derive from the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/\">Node<\/a> class, which is the base class in the Aspose.Words Document Object Model.<\/li>\n<li>Nodes that can contain other nodes, for example, <strong>Section<\/strong> or <strong>Paragraph<\/strong>, derive from the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/\">CompositeNode<\/a> class, which in turn derives from the <strong>Node<\/strong> class.<\/li>\n<\/ul>\n<p>The diagram provided below shows inheritance between node classes of the Aspose.Words Document Object Model (DOM). The names of abstract classes are in Italics.<\/p>\n<img src=\"aspose-words-dom.png\" alt=\"aspose-words-dom\" style=\"width:700px\"\/>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nThe Aspose.Words DOM also contains the non-node classes, such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/style\/\">Style<\/a> or <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/\">Font<\/a>, which are used to customize the appearance and styles  within a document. These classes are not shown in this diagram as not inherited from the <code>Node<\/code> class.\n<\/div>\n\n<p>Let&rsquo;s look at an example. The following image shows a Microsoft Word document with different types of content.<\/p>\n<img src=\"document-example.png\" alt=\"document-example\" style=\"width:700px\"\/>\n<p>When reading the above document into the Aspose.Words DOM, the tree of objects is created, as shown in the schema below.<\/p>\n<img src=\"document-example-dom.png\" alt=\"document-example-dom\" style=\"width:700px\"\/>\n<p><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/\">Section<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraph\/\">Paragraph<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/table\/\">Table<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/\">Shape<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/run\/\">Run<\/a>, and all other ellipses on the diagram are Aspose.Words objects that represent elements of the Word document.<\/p>\n<h3 id=\"get-a-node-type\">Get a <code>Node<\/code> Type<\/h3>\n<p>Although the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/\">Node<\/a> class is sufficient enough to distinguish different nodes from each other, Aspose.Words provides the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/nodetype\/\">NodeType<\/a> enumeration to simplify some API tasks, such as selecting nodes of a specific type.<\/p>\n<p>The type of each node can be obtained using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getNodeType\">NodeType<\/a> property. This property returns a <strong>NodeType<\/strong> enumeration value. For example, a paragraph node represented by the <strong>Paragraph<\/strong> class returns <strong>NodeType<\/strong>.<strong>Paragraph<\/strong>, and a table node represented by the <strong>Table<\/strong> class returns <strong>NodeType<\/strong>.<strong>Table<\/strong>.<\/p>\n<p>The following example shows how to get a node type using the <strong>NodeType<\/strong> enumeration:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-document_object_model-GetNodeType-.java\"><\/script>\n\n<h2 id=\"document-tree-navigation\">Document Tree Navigation<\/h2>\n<p>Aspose.Words represents a document as a node tree, which enables you to navigate between nodes. This section describes how to explore and navigate the document tree in Aspose.Words.<\/p>\n<p>When you open the sample document, presented earlier, in the Document Explorer, the node tree appears exactly as it is represented in Aspose.Words.<\/p>\n<img src=\"document-in-document-explorer.png\" alt=\"document-in-document-explorer\" style=\"width:680px\"\/>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can learn the sample project &ldquo;Document Explorer&rdquo; on the <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/tree\/master\/Examples\/DocsExamples\/Java\/src\/main\/java\/DocsExamples\/Document_explorer\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<h3 id=\"document-nodes-relationships\">Document Node Relationships<\/h3>\n<p>The nodes in the tree have relationships between them:<\/p>\n<ul>\n<li>A node containing another node is a <em>parent.<\/em><\/li>\n<li>The node contained in the parent node is a <em>child.<\/em> Child nodes of the same parent are <em>sibling<\/em> nodes.<\/li>\n<li>The <em>root<\/em> node is always the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> node.<\/li>\n<\/ul>\n<p>The nodes that can contain other nodes derive from the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/\">CompositeNode<\/a> class, and all nodes ultimately derive from the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/\">Node<\/a> class. These two base classes provide common methods and properties for the tree structure navigation and modification.<\/p>\n<p>The following UML object diagram shows several nodes of the sample document and their relations to each other via the parent, child, and sibling properties:<\/p>\n<img src=\"document-nodes-relationships.png\" alt=\"document-nodes-relationships\" style=\"width:370px\"\/>\n<h4 id=\"document-is-node-owner\">Document is Node Owner<\/h4>\n<p>A node always belongs to a particular document, even if it has been just created or removed from the tree, because vital document-wide structures such as styles and lists are stored in the <strong>Document<\/strong> node. For example, it is not possible to have a <strong>Paragraph<\/strong> without a <strong>Document<\/strong> because each paragraph has an assigned style that is defined globally for the document. This rule is used when creating any new nodes. Adding a new <strong>Paragraph<\/strong> directly to the DOM requires a document object passed to the constructor.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nThe <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getDocument\">Node.Document<\/a> property returns the document to which the node belongs.\n<\/div>\n\n<p>When creating a new paragraph using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a>, the builder always has a <strong>Document<\/strong> class linked to it through the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#Document\">DocumentBuilder.Document<\/a> property.<\/p>\n<p>The following code example shows that when creating any node, a document that will own the node is always defined:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-document_object_model-OwnerDocument-.java\"><\/script>\n\n<h4 id=\"parent-node\">Parent Node<\/h4>\n<p>Each node has a parent specified by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getParentNode\">ParentNode<\/a> property. A node has no parent node, that is, <strong>ParentNode<\/strong> is null, in the following cases:<\/p>\n<ul>\n<li>The node has just been created and has not yet been added to the tree.<\/li>\n<li>The node has been removed from the tree.<\/li>\n<li>This is the root <strong>Document<\/strong> node which always has a null parent node.<\/li>\n<\/ul>\n<p>You can remove a node from its parent by calling the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#remove\">Remove<\/a> method.The following code example shows how to access the parent node:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-document_object_model-AccessParentNode-.java\"><\/script>\n\n<h4 id=\"child-nodes\">Child Nodes<\/h4>\n<p>The most efficient way to access child nodes of a <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/\">CompositeNode<\/a> is via the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/#FirstChild\">FirstChild<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/#LastChild\">LastChild<\/a> properties that return the first and last child nodes, respectively. If there are no child nodes, these properties return <em>null<\/em>.<\/p>\n<p><strong>CompositeNode<\/strong> also provides the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/#getChildNodes\">ChildNodes<\/a> collection enabling indexed or enumerated access to the child nodes. The <strong>ChildNodes<\/strong> property is a live collection of nodes, which means that whenever the document is changed, such as when nodes are removed or added, the <strong>ChildNodes<\/strong> collection is automatically updated.<\/p>\n<p>If a node has no child, then the <strong>ChildNodes<\/strong> property returns an empty collection. You can check whether the <strong>CompositeNode<\/strong> contains any child nodes using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/#hasChildNodes\">HasChildNodes<\/a> property.<\/p>\n<p>The following code example shows how to enumerate immediate child nodes of a <code>CompositeNode<\/code> using the enumerator provided by the <code>ChildNodes<\/code> collection:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-document_object_model-ChildNodes-enumerateChildrenOfACompositeNodeUsingEnumeratorProvidedByChildNodesCollection.java\"><\/script>\n\n<p>The following code example shows how to enumerate immediate child nodes of a <code>CompositeNode<\/code> using indexed access:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-document_object_model-ChildNodes-enumerateChildrenOfACompositeNodeUsingIndexedAccess.java\"><\/script>\n\n<h4 id=\"sibling-nodes\">Sibling Nodes<\/h4>\n<p>You can obtain the node that immediately precedes or follows a particular node using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getPreviousSibling\">PreviousSibling<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getNextSibling\">NextSibling<\/a> properties, respectively. If a node is the last child of its parent, then the <strong>NextSibling<\/strong> property is <em>null<\/em>. Conversely, if the node is the first child of its parent, the <strong>PreviousSibling<\/strong> property is <em>null<\/em>.<\/p>\n<p>The following code example shows how to efficiently visit all direct and indirect child nodes of a composite node:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-document_object_model-SiblingNodes-.java\"><\/script>\n\n<h3 id=\"typed-access-to-child-and-parent-nodes\">Typed Access to Child and Parent Nodes<\/h3>\n<p>So far, we have discussed the properties that return one of the base types \u2013 <strong>Node<\/strong> or <strong>CompositeNode<\/strong>. But sometimes there are situations where you might need to cast values to a specific node class, such as <strong>Run<\/strong> or <strong>Paragraph<\/strong>. That is, you cannot completely get away from casting when working with the Aspose.Words DOM, which is composite.<\/p>\n<p>To reduce the need for casting, most Aspose.Words classes provide properties and collections that provide strongly-typed access. There are three basic patterns of typed access:<\/p>\n<ul>\n<li>A parent node exposes typed <strong>FirstXXX<\/strong> and <strong>LastXXX<\/strong> properties. For example, the <strong>Document<\/strong> has <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getFirstSection\">FirstSection<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getLastSection\">LastSection<\/a> properties. Similarly, <strong>Table<\/strong> has properties such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/table\/#getFirstRow\">FirstRow<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/table\/#getLastRow\">LastRow<\/a>, and others.<\/li>\n<li>A parent node exposes a typed collection of child nodes, such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getSections\">Document.Sections<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/story\/#getParagraphs\">Body.Paragraphs<\/a>, and others.<\/li>\n<li>A child node provides typed access to its parent, such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/inline\/#getParentParagraph\">Run.ParentParagraph<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraph\/#getParentSection\">Paragraph.ParentSection<\/a>, and others.<\/li>\n<\/ul>\n<p>Typed properties are merely useful shortcuts that sometimes provide easier access than generic properties inherited from <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getParentNode\">Node.ParentNode<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/#getFirstChild\">CompositeNode.FirstChild<\/a>.<\/p>\n<p>The following code example shows how to use typed properties to access nodes of the document tree:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-document_object_model-TypedAccessToChildrenAndParent-.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I determine the type of a node (e.g., Paragraph, Table) in the DOM?<br>\n<strong>A:<\/strong> Call <code>Node.getNodeType()<\/code>, which returns a value from the <code>NodeType<\/code> enumeration such as <code>NodeType.Paragraph<\/code> or <code>NodeType.Table<\/code>. This lets you identify the node without casting.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What properties let me navigate to a node\u2019s parent, children, or siblings?<br>\n<strong>A:<\/strong> Use <code>Node.getParentNode()<\/code> for the parent, <code>CompositeNode.getFirstChild()<\/code> \/ <code>CompositeNode.getLastChild()<\/code> for the first and last child, <code>CompositeNode.getChildNodes()<\/code> for the full collection, and <code>Node.getPreviousSibling()<\/code> \/ <code>Node.getNextSibling()<\/code> for adjacent siblings.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I create a new node (for example, a Paragraph) and add it to a document?<br>\n<strong>A:<\/strong> Instantiate the node with a reference to the owning <code>Document<\/code>, e.g., <code>Paragraph paragraph = new Paragraph(document);<\/code>, then insert it using <code>parentNode.appendChild(paragraph);<\/code> or by using <code>DocumentBuilder<\/code> methods such as <code>builder.writeln(&quot;Text&quot;);<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I clone or copy a node to another location or another document?<br>\n<strong>A:<\/strong> Use <code>Node.deepClone()<\/code> to duplicate a node within the same document. To move a node to a different document, call <code>Document.importNode(node, true)<\/code> on the target document and then append the imported node to the desired parent.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to use <code>DocumentBuilder<\/code> to navigate to a specific node in the DOM?<br>\n<strong>A:<\/strong> Yes. After obtaining a reference to the target node, call <code>builder.moveTo(node);<\/code>. You can also use <code>builder.moveToDocumentStart()<\/code> or <code>builder.moveToDocumentEnd()<\/code> to position the builder at the beginning or end of the document before inserting new content.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Translate Markdown to DOM","link":"https:\/\/docs.aspose.com\/words\/java\/translate-markdown-to-document-object-model\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/translate-markdown-to-document-object-model\/","description":"\n        \n        \n        <p>To programmatically read, manipulate, and modify the content and formatting of a document, you need to translate it to the Aspose.Words Document Object Model (DOM).<\/p>\n<p>In contrast to Word documents, Markdown does not conform to the DOM described in the <a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/aspose-words-document-object-model\/\">Aspose.Words Document Object Model (DOM)<\/a> article. However, Aspose.Words provides its own mechanism for translating Markdown documents to DOM and back, so that we can successfully work with their elements such as text formatting, tables, headers, and others.<\/p>\n<p>This article explains how the various markdown features can be translated into Aspose.Words DOM and back to Markdown format.<\/p>\n<h2 id=\"complexity-of-translation-markdown--dom--markdown\">Complexity of Translation Markdown \u2013 DOM \u2013 Markdown<\/h2>\n<p>The main difficulty of this mechanism is not only to translate Markdown to DOM, but also to do the reverse transformation \u2013 to save the document back to Markdown format with minimal loss. There are elements, such as multilevel quotes, for which the reverse transformation is not trivial.<\/p>\n<p>Our translation engine allows users not only to work with complex elements in an existing Markdown document, but also to create their own document in Markdown format with the original structure from scratch. To create various elements, you need to use styles with specific names according to certain rules described later in this article. Such styles can be created programmatically.<\/p>\n<h2 id=\"common-translation-principles\">Common Translation Principles<\/h2>\n<p>We use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/\">Font<\/a> formatting for inline blocks. When there is no direct correspondence for a Markdown feature in Aspose.Words DOM, we use a character style with a name that starts from some special words.<\/p>\n<p>For container blocks, we use style inheritance to denote nested Markdown features. In this case, even when there are no nested features, we also use paragraph styles with a name that starts from some special words.<\/p>\n<p>Bulleted and ordered lists are container blocks in Markdown as well. Their nesting is represented in DOM the same way as for all other container blocks using style inheritance. However, additionally, lists in DOM have corresponded number formatting in either list style or paragraph formatting.<\/p>\n<h2 id=\"inline-blocks\">Inline Blocks<\/h2>\n<p>We use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/\">Font<\/a> formatting when translating <strong>Bold<\/strong>, <em>Italic<\/em> or <del>Strikethrough<\/del> inline markdown features.<\/p>\n<table>\n<thead>\n<tr>\n<th>Markdown feature<\/th>\n<th>Aspose.Words<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Bold<\/strong><br \/><code>**bold text**<\/code><\/td>\n<td><code>Font.Bold = true<\/code><\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-BoldText.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Italic<\/strong><br \/><code>*italic text*<\/code><\/td>\n<td><code>Font.Italic = true<\/code><\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-ItalicText.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Strikethrough<\/strong><br \/><code>~Strikethrough text~<\/code><\/td>\n<td><code>Font.StrikeThrough = true<\/code><\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-Strikethrough.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>We use a character style with a name that starts from the word <code>InlineCode<\/code>, followed by an optional dot <code>(.)<\/code> and a number of backticks <code>(`)<\/code> for the <code>InlineCode<\/code> feature. If a number of backticks is missed, then one backtick will be used by default.<\/p>\n<table>\n<thead>\n<tr>\n<th>Markdown feature<\/th>\n<th>Aspose.Words<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>InlineCode<\/strong><br \/><code>**inline code**<\/code><\/td>\n<td><code>Font.StyleName = \u201cInlineCode[.][N]\u201d<\/code><\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-InlineCode.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Autolink<\/strong><br \/><code>&lt;scheme:\/\/domain.com&gt;<\/code><br \/><code>&lt;email@domain.com&gt;<\/code><\/td>\n<td>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/fieldhyperlink\/\">FieldHyperlink<\/a> class.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-Autolink.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Link<\/strong><br \/><code>[link text](url)<\/code><br \/><code>[link text](&lt;url&gt; &quot;title&quot;)<\/code><br \/><code>[link text](url 'title')<\/code><br \/><code>[link text](url (title))<\/code><\/td>\n<td>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/fieldhyperlink\/\">FieldHyperlink<\/a> class.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-Link.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Image<\/strong><br \/><code>![](url)<\/code><br \/><code>![alt text](&lt;url&gt; \u201ctitle\u201d)<\/code><br \/><code>![alt text](url \u2018title\u2019)<\/code><br \/><code>![alt text](url (title))<\/code><\/td>\n<td>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/\">Shape<\/a> class.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-Image.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"container-blocks\">Container Blocks<\/h2>\n<p>A document is a sequence of container blocks such as headings, paragraphs, lists, quotes, and others. Container blocks can be divided into 2 classes: Leaf blocks and Complex Containers. Leaf blocks can only contain inline content. Complex containers, in turn, can contain other container blocks, including Leaf blocks.<\/p>\n<h3 id=\"leaf-blocks\">Leaf Blocks<\/h3>\n<p>The table below shows examples of using Markdown Leaf blocks in Aspose.Words:<\/p>\n<table>\n<thead>\n<tr>\n<th>Markdown feature<\/th>\n<th>Aspose.Words<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>HorizontalRule<\/strong><br \/><code>-----<\/code><\/td>\n<td>This is a simple paragraph with a corresponding HorizontalRule shape:<br \/><code>DocumentBuilder.InsertHorizontalRule()<\/code><\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-HorizontalRule.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>ATX Heading<\/strong><br \/><code># H1, ## H2, ### H3\u2026<\/code><\/td>\n<td><code>ParagraphFormat.StyleName = &quot;Heading N&quot;<\/code>, where (1&lt;= N &lt;= 9).<br \/>This is translated into a built-in style and should be exactly of the specified pattern (no suffixes or prefixes are allowed).<br \/>Otherwise, it will be just a regular paragraph with a corresponding style.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-Heading.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Setext Heading<\/strong><br \/><code>===<\/code> (if Heading level 1),<br \/><code>---<\/code> (if Heading level 2)<\/td>\n<td><code>ParagraphFormat.StyleName = \u201cSetextHeading[some suffix]\u201d<\/code>, based on &lsquo;Heading N&rsquo; style.<br \/>If (N &gt;= 2), then &lsquo;Heading 2&rsquo; will be used, otherwise &lsquo;Heading 1&rsquo;.<br \/>Any suffix is allowed, but Aspose.Words importer uses numbers \u201c1\u201d and \u201c2\u201d respectively.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-SetextHeading.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Indented Code<\/strong><br><div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"o\">&lt;<\/span><span class=\"n\">br<\/span><span class=\"o\">\/&gt;<\/span><span class=\"k\">if<\/span> <span class=\"o\">()&lt;<\/span><span class=\"n\">br<\/span><span class=\"o\">\/&gt;<\/span><span class=\"n\">then<\/span><span class=\"o\">&lt;<\/span><span class=\"n\">br<\/span><span class=\"o\">\/&gt;<\/span><span class=\"k\">else<\/span><span class=\"o\">&lt;<\/span><span class=\"n\">br<\/span><span class=\"o\">\/&gt;<\/span><span class=\"err\">```<\/span><\/code><\/pre><\/div><\/td>\n<td><code>ParagraphFormat.StyleName = \u201cIndentedCode[some suffix]\u201d<\/code><\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-FencedCode.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"complex-containers\">Complex Containers<\/h3>\n<p>The table below shows examples of using Markdown Complex Containers in Aspose.Words:<\/p>\n<table>\n<thead>\n<tr>\n<th>Markdown feature<\/th>\n<th>Aspose.Words<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Quote<\/strong><br \/><code>&gt; quote,<\/code><br \/><code>&gt;&gt; nested quote<\/code><\/td>\n<td><code>ParagraphFormat.StyleName = \u201cQuote[some suffix]\u201d<\/code><br \/>The suffix in style name is optional, but Aspose.Words importer uses the ordered numbers 1, 2, 3, \u2026. in case of nested quotes.<br \/>The nesting is defined via the inherited styles.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-Quote.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>BulletedList<\/strong><br \/><code>- Item 1<\/code><br \/><code>- Item 2<\/code><br \/>\t<code>   - Item 2a<\/code><br \/>\t<code>   - Item 2b<\/code><\/td>\n<td>Bulleted lists are represented using paragraph numbering:<br \/><code>ListFormat.ApplyBulletDefault()<\/code><br \/>There can be 3 types of bulleted lists. They are only diff in a numbering format of the very first level. These are: <code>\u2018-\u2019<\/code>, <code>\u2018+\u2019<\/code> or <code>\u2018*\u2019<\/code> respectively.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-BulletedList.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>OrderedList<\/strong><br \/><code>1. Item 1<\/code><br \/><code>2. Item 2<\/code><br \/>\t<code>1) Item 2a<\/code><br \/>\t<code>2) Item 2b<\/code><\/td>\n<td>Ordered lists are represented using paragraph numbering:<br \/><code>ListFormat.ApplyNumberDefault()<\/code><br \/>There can be 2 number format markers: \u2018.\u2019 and \u2018)\u2019. The default marker is \u2018.\u2019.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-OrderedList.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"tables\">Tables<\/h3>\n<p>Aspose.Words also allows to translate tables into DOM, as shown below:<\/p>\n<table>\n<thead>\n<tr>\n<th>Markdown feature<\/th>\n<th>Aspose.Words<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>Table<\/code><br \/><code>a|b<\/code><br \/><code>-|-<\/code><br \/><code>c|d<\/code><\/td>\n<td><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/table\/\">Table<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/row\/\">Row<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/cell\/\">Cell<\/a> classes.<\/td>\n<\/tr>\n<tr>\n<td><script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertDocumentToMarkdown-Table.java\"><\/script>\n<\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"see-also\">See Also<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/working-with-markdown-features\/\">Working with Markdown Features<\/a><\/li>\n<\/ul>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I convert a Markdown file to a Word document using Aspose.Words for Java?<br>\n<strong>A:<\/strong> Load the Markdown file with <code>Document doc = new Document(&quot;input.md&quot;);<\/code> and then save it in a Word format, e.g., <code>doc.save(&quot;output.docx&quot;);<\/code>. The library automatically parses the Markdown and builds the corresponding DOM.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to convert a Word document back to Markdown?<br>\n<strong>A:<\/strong> Yes. After loading a Word document (<code>Document doc = new Document(&quot;input.docx&quot;);<\/code>), call <code>doc.save(&quot;output.md&quot;);<\/code>. Aspose.Words will translate the DOM back to Markdown, preserving supported elements.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Which style names are used for Markdown headings when they are imported?<br>\n<strong>A:<\/strong> Headings are mapped to built\u2011in styles named <code>Heading 1<\/code> \u2026 <code>Heading 9<\/code>. The importer expects the exact pattern without extra prefixes or suffixes; otherwise the text is treated as a normal paragraph.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How are bulleted and ordered lists represented in the DOM?<br>\n<strong>A:<\/strong> Bulleted lists use <code>ListFormat.applyBulletDefault();<\/code> while ordered lists use <code>ListFormat.applyNumberDefault();<\/code>. The first\u2011level marker can be <code>-<\/code>, <code>+<\/code>, <code>*<\/code> for bullets and <code>.<\/code> or <code>)<\/code> for numbers.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What classes are used for images and hyperlinks during conversion?<br>\n<strong>A:<\/strong> Images become <code>Shape<\/code> objects (<code>Shape shape = new Shape(doc, ShapeType.IMAGE);<\/code>). Hyperlinks and autolinks are represented by <code>FieldHyperlink<\/code> fields, which can be accessed via <code>FieldHyperlink field = (FieldHyperlink) node;<\/code>.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Document Builder Overview in Java","link":"https:\/\/docs.aspose.com\/words\/java\/document-builder-overview\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/document-builder-overview\/","description":"\n        \n        \n        <p><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> is a powerful class that associates with <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> and enables you to build dynamic documents from scratch or add new elements to an existing one.<\/p>\n<p><strong>DocumentBuilder<\/strong> provides methods to insert text, checkboxes, ole objects, paragraphs, lists, tables, images, and other content elements. It allows you to specify fonts, paragraph or section formatting, and perform other operations.<\/p>\n<h2 id=\"document-builder-or-asposewords-dom\">Document Builder or Aspose.Words DOM<\/h2>\n<p><strong>DocumentBuilder<\/strong> complements classes and methods available in the Aspose.Words Document Object Model (DOM) to simplify the most common document building tasks. That is, you can create and modify the content of documents both through the Aspose.Words DOM, which requires a good understanding of the tree structure, and using the DocumentBuilder. The <code>DocumentBuilder<\/code> is a &ldquo;facade&rdquo; for the complex <strong>Document<\/strong> structure that allows you to quickly and easily insert content and formatting.<\/p>\n<p>Operations that are possible with <strong>DocumentBuilder<\/strong> are also possible when using the classes of the Aspose.Words DOM directly. However, using Aspose.Words DOM classes directly usually require more lines of code than using <strong>DocumentBuilder<\/strong>.<\/p>\n<h2 id=\"document-navigation\">Document Navigation<\/h2>\n<p>Document navigation is based on the concept of a virtual cursor, with which you can move to another location in the document using various <strong>DocumentBuilder.MoveToXXX<\/strong> methods such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#moveToDocumentStart\">MoveToDocumentStart<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#moveToField-com.aspose.words.Field-boolean\">MoveToField<\/a>. This virtual cursor indicates where the text will be inserted when calling the methods <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#write-java.lang.String\">Write<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#writeln\">Writeln<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertBreak-int\">InsertBreak<\/a>, and others. See the following article &ldquo;Navigation with Cursor&rdquo; to learn more about the virtual cursor.<\/p>\n<p>The following code example shows how to navigate to a bookmark:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderMoveToBookmarkEnd-DocumentBuilderMoveToBookmarkEnd.java\"><\/script>\n\n<h2 id=\"document-building-and-modifying\">Document Building and Modifying<\/h2>\n<p>Aspose.Words API provides several classes that are responsible for formatting various elements of a document. Each of the classes encapsulates formatting properties related to a specific document element, such as text, paragraph, section, and others. For example, the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/\">Font<\/a> class represents character formatting properties, the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/\">ParagraphFormat<\/a> class represents paragraph formatting properties, and so on. Objects of these classes are returned by the corresponding <strong>DocumentBuilder<\/strong> properties, which have the same names as the classes. Therefore, you can access them and set the desired formatting during the document build.<\/p>\n<p>You can also insert text, checkbox, ole object, images, bookmarks, form fields, and other document elements at the cursor position using the <code>Write<\/code> method or any of the <strong>DocumentBuilder.InsertXXX<\/strong> methods, such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertField-int-boolean\">InsertField<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertHtml-java.lang.String\">InsertHtml<\/a>, and similar methods.<\/p>\n<p>Let&rsquo;s see how to create a simple document using the <strong>DocumentBuilder<\/strong>.<\/p>\n<h3 id=\"create-a-document-using-documentbuilder\">Create a Document using DocumentBuilder<\/h3>\n<p>To start, you need to create a <strong>DocumentBuilder<\/strong> and associate it with a <strong>Document<\/strong> object. You create a new instance of <strong>DocumentBuilder<\/strong> by calling its constructor and pass it to a <strong>Document<\/strong> object for attachment to the builder.<\/p>\n<p>To insert a text, pass the string of text you need to insert into the document to the <strong>Write<\/strong> method.<\/p>\n<p>The following code example shows how to create a simple document using a document builder.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-quickstart-HelloWorld-CreateNewDocument.java\"><\/script>\n\n<h3 id=\"specify-document-formatting\">Specify Document Formatting<\/h3>\n<p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getFont\">Font<\/a> property defines text formatting. This object contains different font attributes (font name, font size, color, and so on). Some important font attributes are also represented by <strong>DocumentBuilder<\/strong> properties to allow you to access them directly. These are the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/#getBold\">Font.Bold<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/#getItalic\">Font.Italic<\/a>, and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/#getUnderline\">Font.Underline<\/a> boolean properties.<\/p>\n<p>The following code example shows how to insert a formatted text using <strong>DocumentBuilder<\/strong>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-DocumentBuilderInsertParagraph.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\n<ul>\n<li><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getFont\">Font<\/a> specifies the character formatting that will be applied to all text inserted from the current position in the document onwards.<\/li>\n<li><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/\">ParagraphFormat<\/a> specifies the paragraph formatting for the current and all paragraphs to be inserted.<\/li>\n<li><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/\">PageSetup<\/a> specifies the page and section properties for the current section and the entire section that will be inserted.<\/li>\n<li><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getCellFormat\">CellFormat<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getRowFormat\">RowFormat<\/a> specify formatting properties that will be applied to table cells and rows from the current position in the document onwards.<\/li>\n<\/ul>\n<p>In this situation, &ldquo;current&rdquo; means the position, paragraph, section, cell, or row in which the cursor is.\n<\/div>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the <strong>Font<\/strong>, <strong>ParagraphFormat<\/strong>, and <strong>PageSetup<\/strong> properties are updated whenever you navigate to a different location in the document to reflect the formatting properties of this location.\n<\/div>\n\n\n      "},{"title":"Java: Working with Document in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-document\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-document\/","description":"\n        \n        \n        <p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> class is central in Aspose.Words. It represents a document and provides various document properties and methods, such as saving or protecting the document. You use the <strong>Document<\/strong> class as the starting point for whatever you want to perform with Aspose.Words: create a new document from scratch, open a template for a mail merge, or get different parts from a document.<\/p>\n<p>The <strong>Document<\/strong> object contains all content and formatting, styles, built-in and custom properties, and the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/mailmerge\/\">MailMerge<\/a> object that is used for a mail merge. <strong>Document<\/strong> enables you to retrieve text, bookmarks, and form fields for the entire document or separate sections.<\/p>\n<p><strong>Document<\/strong> contains a collection of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/\">Section<\/a> objects enabling you to obtain a particular section or perform some manipulations such as copying or moving sections. The <strong>Document<\/strong> object can be saved at any time to a file or stream and also sent to a client browser.<\/p>\n\n      "},{"title":"Java: Protect or Encrypt a Document in Java","link":"https:\/\/docs.aspose.com\/words\/java\/protect-or-encrypt-a-document\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/protect-or-encrypt-a-document\/","description":"\n        \n        \n        <p>The main reason to protect or encrypt a document is to apply more control over who can access the document or who can edit it. Applying protection to your documents, you avoid common risks such as copying or modifying documents without permission, as well as data leakage.<\/p>\n<p>Some of the most popular formats when working with documents are Microsoft Word formats or formats that can be exported from Word. That&rsquo;s why many users are interested in the same document protection options that Microsoft Word provides. Despite the complexity of these options, Aspose.Words supports most of them, so it makes it an excellent solution for working with documents.<\/p>\n<p>This article describes what options Aspose.Words provides for document protection and how these options are presented in the familiar Microsoft Word user interface. In the child articles of the current section, you can learn more about the listed protection functions with all the necessary properties and methods.<\/p>\n<h2 id=\"document-protection-options\">Document Protection Options<\/h2>\n<p>Aspose.Words currently provides the document features listed in the table below. You can find the details on each of the features in the corresponding child article in the current section.<\/p>\n<table>\n<thead>\n<tr>\n<th>Aspose.Words protection feature<\/th>\n<th>Corresponding child article<\/th>\n<th>Corresponding MS Word feature<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Read-Only<\/td>\n<td>\u201cMake a Document Read-Only\u201d<\/td>\n<td>Always Open Read-Only (File \u2192 Info \u2192 Protect Document)<br \/>Alternative feature: &ldquo;Password to modify&rdquo; (Save As \u2192 Tools \u2192 General Options \u2192 Password)<\/td>\n<\/tr>\n<tr>\n<td>Encrypt a Document<\/td>\n<td>\u201cEncrypt a Document\u201d<\/td>\n<td>Encrypt with Password (File \u2192 Info \u2192 Protect Document)<br \/>Alternative feature: &ldquo;Password to open&rdquo; (Save As \u2192 Tools \u2192 General Options \u2192 Password)<\/td>\n<\/tr>\n<tr>\n<td>Restrict Editing<\/td>\n<td>\u201cRestrict Document Editing\u201d<\/td>\n<td>Restrict Editing (File \u2013 Info \u2013 Protect Document)<br \/>Alternative feature: &ldquo;Restrict Editing&rdquo; (Review \u2192 Protect \u2192 Restrict Editing)<\/td>\n<\/tr>\n<tr>\n<td>Digital Signatures<\/td>\n<td>\u201cWork with Digital Signatures\u201d<\/td>\n<td>Add a Digital Signature (File \u2192 Info \u2192 Protect Document)<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that Aspose.Words does not support both Microsoft Word features \u201cMark as Final\u201d and \u201cRestrict Access\u201d.\n<\/div>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the exact names of features and the paths to them in Microsoft Word may differ depending on the version, we try to provide users with the latest data.\n<\/div>\n\n<h2 id=\"see-also\">See Also<\/h2>\n<ul>\n<li>Try our <a href=\"https:\/\/products.aspose.app\/words\/unlock\">Free online documents unlocker<\/a><\/li>\n<\/ul>\n\n      "},{"title":"Java: Compare Documents in Java","link":"https:\/\/docs.aspose.com\/words\/java\/compare-documents\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/compare-documents\/","description":"\n        \n        \n        <p>Comparing documents is a process that identifies changes between two documents and contains the changes as revisions. This process compares any two documents, including versions of one specific document, then the changes between both documents will be shown as revisions in the first document.<\/p>\n<p>The comparison method is achieved by comparing words at the character level or at the word level. If a word contains a change of at least one character, in the result, the difference will be displayed as a change of the entire word, not a character. This process of comparison is a usual task in the legal and financial industries.<\/p>\n<p>Instead of manually searching for differences between documents or between different versions of them, you can use Aspose.Words for comparing documents and getting content changes in formatting, header\/footer, tables, and more.<\/p>\n<p>This article explains how to compare documents and how to specify advanced comparing properties.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\n<p><strong>Try online<\/strong><\/p>\n<p>You can compare two documents online by using the <a href=\"https:\/\/products.aspose.app\/words\/comparison\">Document comparison online<\/a> tool.<\/p>\n<p>Note that the comparison method, described below, is used in this tool to ensure getting equal results. So you will get the same results even by using the online comparison tool or by using the comparison method in Aspose.Words.<\/p>\n\n<\/div>\n\n<h2 id=\"limitations-and-supported-file-formats\">Limitations and Supported File Formats<\/h2>\n<p>Comparing documents is a very complex feature. There are varied parts of content combination that need to be analyzed to recognize all differences. The reason for this complexity is because Aspose.Words aims to get the same comparison results as the Microsoft Word comparison algorithm.<\/p>\n<p>The general limitation for two documents being compared is that they must not have revisions before calling the compare method as this limitation exists in Microsoft Word.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that you can compare any two documents within the <a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/supported-document-formats\/\">supported file formats<\/a>. Basically, you can compare document objects and even you can create those objects from scratch without having any specific format.\n<\/div>\n\n<h2 id=\"compare-two-documents\">Compare Two Documents<\/h2>\n<p>When you compare documents, differences of the latter document from the former show up as revisions to the former. When you modify a document, each edit will have its own revision after running the compare method.<\/p>\n<p>Aspose.Words allows you to identify documents differences using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#compare-com.aspose.words.Document-java.lang.String-java.util.Date\">Compare<\/a> method \u2013 this is similar to the Microsoft Word document compare feature. It allows you to check documents or document versions to find differences and changes, including formatting modifications such as font changes, spacing changes, the addition of words and paragraphs.<\/p>\n<p>As a result of the comparison, documents can be determined as equal or not equal. The term \u201cequal\u201d documents mean that the comparison method is not able to represent changes as revisions. This means that both document text and text formatting are the same. But there can be other differences between documents. For example, Microsoft Word supports only format revisions for styles, and you cannot represent style insertion\/deletion. So documents can have a different set of styles, and the <strong>Compare<\/strong> method still produces no revisions.<\/p>\n<p>The following code example shows how to check if two documents are equal or not:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-CompareTwoWordDocuments-wordDocumentsAreEqual.java\"><\/script>\n\n<p>The following code example shows how to simply apply the <code>Compare<\/code> method to two documents:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-CompareTwoWordDocuments-caseWhenDocumentHasRevisions.java\"><\/script>\n\n<h2 id=\"specify-advanced-comparing-properties\">Specify Advanced Comparison Options<\/h2>\n<p>There are many different properties of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compareoptions\/\">CompareOptions<\/a> class which you can apply when you want to compare documents.<\/p>\n<p>For example, Aspose.Words allows you to ignore changes made during a comparison operation for certain types of objects within the original document. You can select the appropriate property for the object type, such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compareoptions\/#getIgnoreHeadersAndFooters\">IgnoreHeadersAndFooters<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compareoptions\/#getIgnoreFormatting\">IgnoreFormatting<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compareoptions\/#getIgnoreComments\">IgnoreComments<\/a>, and others by setting them to &ldquo;true&rdquo;.<\/p>\n<p>In addition, Aspose.Words provides the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compareoptions\/#getGranularity\">Granularity<\/a> property with which you can specify whether to track changes by character or by word.<\/p>\n<p>Another common property is a choice in which document to show comparison changes. For example, the \u201cCompare documents dialogue box\u201d in Microsoft Word has the option \u201cShow changes in\u201d \u2013 this also affects the comparison results. Aspose.Words provides the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compareoptions\/#getTarget\">Target<\/a> property that serves this purpose.<\/p>\n<p>The following code example shows how to set the advanced comparing properties:\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-CompareTwoWordDocuments-AdvancedComparingProperties.java\"><\/script>\n<\/p>\n\n      "},{"title":"Java: Clone a Document in Java","link":"https:\/\/docs.aspose.com\/words\/java\/clone-a-document\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/clone-a-document\/","description":"\n        \n        \n        <p>Cloning a document is the process of creating an identical copy of an original document, which can improve performance and save you from potential memory leaks.<\/p>\n<p>This article will explain the main use cases of cloning a document and how to create a document clone using Aspose.Words.<\/p>\n<h2 id=\"operations-with-cloning-documents\">Operations with Cloning Documents<\/h2>\n<p>The clone operation allows you to make the process of creating documents faster as you will not need to load and parse a document from a file every time.<\/p>\n<p>After creating a clone of your document, you will be able to edit it and perform different operations on it, for example, compare it with the original document, append or insert it into another document. You can also modify cloned elements or their content before inserting them into another document.<\/p>\n<h2 id=\"creating-a-document-clone\">Creating a Document Clone<\/h2>\n<p>Aspose.Words allows you to clone a document using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#deepClone\">Clone<\/a> method that performs a deep copy of the document and returns it. In other words, it will get a full copy of the DOM. The <code>Clone<\/code> method speeds up the documents generation, and you only need one line of code to get a copy of your document.<\/p>\n<p>Cloning produces a new document with the same contents as the original, but with a unique copy of each of the original document&rsquo;s <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/\">nodes<\/a>. You can also apply the clone operation to a document node by using the node <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#deepClone-boolean\">Clone<\/a> method, which allows you to duplicate composite document nodes with and without their child nodes.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that when applying the cloning method all document properties will be cloned.\n<\/div>\n\n<p>The following code example shows how to clone a document and create a duplicate of a section in that document:\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-CloneDocument-CloneADocument.java\"><\/script>\n<\/p>\n\n      "},{"title":"Java: Working with Watermark in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-watermark\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-watermark\/","description":"\n        \n        \n        <p>This topic discusses how to work programmatically with a watermark using Aspose.Words. A watermark is a background image that displays behind the text in a document.\u00a0A watermark can contain a text or an image represented by the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/watermark\/\">Watermark<\/a>\u00a0class.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\n<p><strong>Try online<\/strong><\/p>\n<p>You can try this functionality with our <a href=\"https:\/\/products.aspose.app\/words\/watermark\">Free online document watermark<\/a>.<\/p>\n\n<\/div>\n\n<h2 id=\"add-a-watermark-to-a-document\">Add a Watermark to a Document<\/h2>\n<p>In Microsoft Word, a watermark can easily be inserted in a document using the Insert Watermark command. Aspose.Words provides the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/watermark\/\">watermark<\/a>\u00a0class to add or remove watermark in documents. Aspose.Words provides the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/watermarktype\/\">WatermarkType\u00a0<\/a>enumeration defining three possible types of watermarks (Text, Image, and None) to work with.\u00a0<\/p>\n<h3 id=\"add-text-watermark\">Add Text Watermark<\/h3>\n<p>The following code example demonstrates how to insert a text watermark in a document by defining\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/textwatermarkoptions\/\">TextWatermarkOptions<\/a>\u00a0using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/watermark\/#setText-java.lang.String\">SetText<\/a> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkWithWatermark-AddTextWatermarkWithSpecificOptions.java\"><\/script>\n\n<h3 id=\"add-image-watermark\">Add Image Watermark<\/h3>\n<p>The following code example demonstrates how to insert an image watermark in a document by defining\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/imagewatermarkoptions\/\">ImageWatermarkOptions<\/a>\u00a0using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/watermark\/#setImage-java.awt.image.BufferedImage\">SetImage<\/a> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkWithWatermark-AddImageWatermarkWithSpecificOptions.java\"><\/script>\n\n<p>Image watermark can be inserted as image, string, or stream.<\/p>\n<p>The watermark can also be inserted using shape class as well. It is very easy to insert any shape or image into a header or footer and thus create a watermark of any imaginable type.<\/p>\n<p>The following code example inserts a watermark into a Word document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-images-AddWatermarkToADocument-AddWatermarkToADocument.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Document.doc\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<h2 id=\"remove-watermark-from-a-document\">Remove Watermark from a Document<\/h2>\n<p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/watermark\/\">Watermark<\/a> class provides the <code>Remove<\/code> method to remove the watermark from a document.<\/p>\n<p>The following code examples shows how to remove a watermark from documents:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkWithWatermark-RemoveWatermarkFromDocument.java\"><\/script>\n\n<p>To remove the watermark from a document you have to set only the name of the watermark shape during inserting and then remove the watermark shape by an assigned name.<\/p>\n<p>The following code example show you how to set the name of the watermark shape and remove it from the document:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"c1\">\/\/ Set name to be able to remove it afterwards\n<\/span><span class=\"c1\"><\/span><span class=\"n\">watermark<\/span><span class=\"p\">.<\/span><span class=\"n\">Name<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;WaterMark&#34;<\/span><span class=\"p\">);<\/span>\n<\/code><\/pre><\/div>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-images-RemoveWatermark-RemoveWatermark.java\"><\/script>\n\n<h2 id=\"add-a-watermark-into-a-table-cell\">Add a Watermark into a Table Cell<\/h2>\n<p>Sometimes you need to insert a watermark\/image into a table&rsquo;s cell and display it outside the table, you can use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shapebase\/#isLayoutInCell-boolean\">IsLayoutInCell<\/a> property. This property gets or sets a flag indicating whether the shape is displayed inside a table or outside of it. Note that this property works only when you optimize the document for Microsoft Word 2010 using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compatibilityoptions\/#optimizeFor-int\">OptimizeFor<\/a> method.<\/p>\n<p>The following code example shows how to use this property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-SetShapeLayoutInCell.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I add a watermark to only a specific page in a document?<br>\n<strong>A:<\/strong> Insert the watermark into a header\/footer that is linked only to the desired page (e.g., using a different first\u2011page header). Set the watermark\u2019s <code>Name<\/code> property so you can later remove or modify it without affecting other pages.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I control the opacity of a text or image watermark?<br>\n<strong>A:<\/strong> Yes. Use <code>TextWatermarkOptions.setOpacity(double)<\/code> for text watermarks or <code>ImageWatermarkOptions.setOpacity(double)<\/code> for image watermarks. The value ranges from\u202f0.0\u202f(fully transparent) to\u202f1.0\u202f(fully opaque).<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I remove a watermark that was added without specifying a name?<br>\n<strong>A:<\/strong> If the watermark was added without a name, you can retrieve all shapes of type <code>ShapeType.WATERMARK<\/code> from the document\u2019s headers\/footers and call <code>remove()<\/code> on the matching shape. Naming the watermark when adding it (<code>watermark.Name(&quot;MyMark&quot;)<\/code>) simplifies later removal.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to add a watermark inside a table cell and have it appear behind the cell\u2019s text?<br>\n<strong>A:<\/strong> Yes. Set <code>ShapeBase.setIsLayoutInCell(false)<\/code> on the watermark shape and ensure the document is optimized for Word\u202f2010 (<code>CompatibilityOptions.optimizeFor(CompatibilityOptions.OPTIMIZE_FOR_WORD_2010)<\/code>). This places the watermark outside the cell layout while keeping it visually aligned with the table.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I add a watermark to a document that is being generated in memory (without saving to disk first)?<br>\n<strong>A:<\/strong> Absolutely. Create a <code>Document<\/code> instance from a stream or from scratch, apply the watermark using the <code>Watermark<\/code> class, and then save the document directly to a <code>ByteArrayOutputStream<\/code> or any other output stream. No intermediate file is required.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Insert and Append Documents in Java","link":"https:\/\/docs.aspose.com\/words\/java\/insert-and-append-documents\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/insert-and-append-documents\/","description":"\n        \n        \n        <p>Sometimes it is required to combine several documents into one. You can do this manually or you can use Aspose.Words insert or append feature.<\/p>\n<p>The insert operation allows you to insert the content of previously created documents into a new or existing one.<\/p>\n<p>In turn, the append feature allows you to add a document only at the end of another document.<\/p>\n<p>This article explains how to insert or append a document to another one in different ways and describes the common properties that you can apply while inserting or appending documents.<\/p>\n<h2 id=\"insert-a-document\">Insert a Document<\/h2>\n<p>As mentioned above, in Aspose.Words a document is represented as a tree of nodes, and the operation of inserting one document into another is copying nodes from the first document tree to the second one.<\/p>\n<p>You can insert documents in a variety of locations in different ways. For example, you can insert a document through a replace operation, a merge field during a merge operation, or via a bookmark.<\/p>\n<p>You can also use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertDocument-com.aspose.words.Document-int\">InsertDocument<\/a> or the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertDocumentInline-com.aspose.words.Document-int-com.aspose.words.ImportFormatOptions\">InsertDocumentInline<\/a> method, which is similar to inserting a document in Microsoft Word, to insert a whole document at the current cursor position without any previous importing.<\/p>\n<p>The following code example shows how to insert a document using the <strong>InsertDocument<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-with-builder.java\"><\/script>\n\n<p>The following code example shows how to insert a document using the <strong>InsertDocumentInline<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-inline-with-builder.java\"><\/script>\n\n<p>The following subsections describe the options during which you can insert one document into another.<\/p>\n<h3 id=\"insert-a-document-during-find-and-replace-operation\">Insert a Document During Find and Replace Operation<\/h3>\n<p>You can insert documents while performing find and replace operations. For example, a document can contain paragraphs with the text [INTRODUCTION] and [CONCLUSION]. But in the final document, you need to replace those paragraphs with the content obtained from another external document. To achieve that, you will need to create a handler for the replace event.<\/p>\n<p>The following code example shows how to create a handler for the replacing event to use it later in the inserting process:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-at-replace-handler.java\"><\/script>\n\n<p>The following code example shows how insert content of one document into another during a find and replace operation:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-at-replace.java\"><\/script>\n\n<h3 id=\"insert-a-document-during-mail-merge-operation\">Insert a Document During Mail Merge Operation<\/h3>\n<p>You can insert a document into a merge field during a Mail Merge operation. For example, a Mail Merge template can contain a merge field such as [Summary]. But in the final document, you need to insert content obtained from another external document into this merge field. To achieve that, you will need to create a handler for the merge event.<\/p>\n<p>The following code example shows how to create a handler for the merging event to use it later in the inserting process:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-at-mail-merge-handler.java\"><\/script>\n\n<p>The following code example shows how to insert a document into the merge field using the created handler:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-at-mail-merge.java\"><\/script>\n\n<h3 id=\"insert-a-document-at-bookmark\">Insert a Document at Bookmark<\/h3>\n<p>You can import a text file into a document and insert it right after a bookmark that you have defined in the document. To do this, create a bookmarked paragraph where you want the document to be inserted.<\/p>\n<p>The following coding example shows how to insert the contents of one document to a bookmark in another document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-at-bookmark.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the bookmark should not enclose multiple paragraphs or text that you want them to appear in your final resulting document.\n<\/div>\n\n<h2 id=\"append-a-document\">Append a Document<\/h2>\n<p>You may have a use case where you need to include additional pages from a document to the end of an existing document. To do this, you just need to call the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#appendDocument-com.aspose.words.Document-int\">AppendDocument<\/a> method to add a document to the end of another one.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#appendChild-com.aspose.words.Node\">AppendChild<\/a> is a node level method within a document. For example, you can create a paragraph, set formatting properties, and then append it as a child to the body using the <strong>AppendChild<\/strong> method.\n<\/div>\n\n<p>The following code example shows how to append a document to the end of another document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=keep-source-formatting.java\"><\/script>\n\n<h2 id=\"import-and-insert-nodes-manually\">Import and Insert Nodes Manually<\/h2>\n<p>Aspose.Words allows you to insert and append documents automatically without any previous importing requirements. However, if you need to insert or append a specific node of your document, such as a section or a paragraph, then first you need to import this node manually.<\/p>\n<p>When you need to insert or append one section or paragraph to another, you essentially need to import the nodes of the first document node tree into the second one using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#importNode-com.aspose.words.Node-boolean\">ImportNode<\/a> method. After importing your nodes, you need to use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#insertBefore-com.aspose.words.Node-com.aspose.words.Node\">InsertAfter<\/a> method to insert a new node after\/before the reference node. This allows you to customize the inserting process by importing nodes from a document and inserting it at given positions.<\/p>\n<p>You can also use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#appendChild-com.aspose.words.Node\">AppendChild<\/a> method to add a new specified node to the end of the list of child nodes, for example, if you want to append content at the paragraph level instead of at the section level.<\/p>\n<p>The following code example shows how to manually import nodes and insert them after a specific node using the <strong>InsertAfter<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=insert-document-as-nodes.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nThe import creates a new node that is a copy of the original node and suitable for insertion into the destination document.\n<\/div>\n\n<p>Content is imported into the destination document section by section, which means that settings, such as page setup and headers or footers, are preserved during import. It is also useful to note that you can define formatting settings when you insert or append a document to specify how two documents are joined together.<\/p>\n<h2 id=\"common-properties-for-insert-and-append-documents\">Common Properties for Insert and Append Documents<\/h2>\n<p>Both <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertDocument-com.aspose.words.Document-int\">InsertDocument<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#appendDocument-com.aspose.words.Document-int\">AppendDocument<\/a> methods accept <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatmode\/\">ImportFormatMode<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatoptions\/\">ImportFormatOptions<\/a> as input parameters. The <strong>ImportFormatMode<\/strong> allows you to control how document formatting is merged when you import content from one document into another by selecting different format modes such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatmode\/#USE-DESTINATION-STYLES\">UseDestinationStyles<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatmode\/#KEEP-SOURCE-FORMATTING\">KeepSourceFormatting<\/a>, and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatmode\/#KEEP-DIFFERENT-STYLES\">KeepDifferentStyles<\/a>. The <strong>ImportFormatOptions<\/strong> allows you to select different import options such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatoptions\/#getIgnoreHeaderFooter\">IgnoreHeaderFooter<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatoptions\/#getIgnoreTextBoxes\">IgnoreTextBoxes<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatoptions\/#getKeepSourceNumbering\">KeepSourceNumbering<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatoptions\/#getMergePastedLists\">MergePastedLists<\/a>, and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/importformatoptions\/#getSmartStyleBehavior\">SmartStyleBehavior<\/a>.<\/p>\n<p>Aspose.Words allows you to adjust the visualization of a resulting document when two documents are added together in an insert or append operation by using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/\">Section<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/\">PageSetup<\/a> properties. The <strong>PageSetup<\/strong> property contains all the attributes of a section such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/#getSectionStart\">SectionStart<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/#getRestartPageNumbering\">RestartPageNumbering<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/#getPageStartingNumber\">PageStartingNumber<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/#getOrientation\">Orientation<\/a>, and others. The most common use case is to set the <strong>SectionStart<\/strong> property to define if the added content will appear on the same page or split into a new one.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the <strong>Section<\/strong> and <strong>PageSetup<\/strong> properties do not control how two documents are inserted\/appended together. They only allow you to change the appearance of your result document.\n<\/div>\n\n<p>The following code example shows how to append one document to another while keeping the content from splitting across two pages:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/6e5c8fd2462c6d7ba26da4d9f66ff77b.js?file=different-page-setup.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I insert a whole document at the current cursor position using <code>DocumentBuilder<\/code>?<br>\n<strong>A:<\/strong> Create a <code>DocumentBuilder<\/code> for the destination document, load the source document, and call <code>builder.insertDocument(sourceDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);<\/code>. The <code>ImportFormatMode<\/code> determines how styles are merged.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I insert a document while performing a find\u2011and\u2011replace operation?<br>\n<strong>A:<\/strong> Implement the <code>IReplacingCallback<\/code> interface, and in the <code>replacing<\/code> method obtain the <code>DocumentBuilder<\/code> from the <code>ReplacingArgs<\/code>. Then call <code>builder.insertDocument(sourceDoc, ImportFormatMode.USE_DESTINATION_STYLES);<\/code>. Register the callback with <code>findReplaceOptions.setReplacingCallback(myCallback);<\/code> before executing <code>document.getRange().replace(findReplaceOptions);<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I insert a document into a merge field during a Mail Merge?<br>\n<strong>A:<\/strong> Implement <code>IFieldMergingCallback<\/code>. In the <code>fieldMerging<\/code> method, move the <code>DocumentBuilder<\/code> to the merge field using <code>builder.moveToMergeField(fieldName);<\/code> and call <code>builder.insertDocument(sourceDoc, ImportFormatMode.KEEP_SOURCE_FORMATTING);<\/code>. Assign the callback to <code>document.getMailMerge().setFieldMergingCallback(myCallback);<\/code> before calling <code>mailMerge.execute(...);<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What is the correct way to insert a document at a bookmark?<br>\n<strong>A:<\/strong> Use <code>DocumentBuilder.moveToBookmark(&quot;MyBookmark&quot;);<\/code> to position the builder at the bookmark, then call <code>builder.insertDocument(sourceDoc, ImportFormatMode.KEEP_DIFFERENT_STYLES);<\/code>. The inserted content will appear immediately after the bookmark.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I control formatting when inserting or appending documents?<br>\n<strong>A:<\/strong> Pass an <code>ImportFormatMode<\/code> (e.g., <code>USE_DESTINATION_STYLES<\/code>, <code>KEEP_SOURCE_FORMATTING<\/code>, <code>KEEP_DIFFERENT_STYLES<\/code>) to <code>insertDocument<\/code> or <code>appendDocument<\/code>. For finer control, create an <code>ImportFormatOptions<\/code> object and set properties such as <code>setIgnoreHeaderFooter(true)<\/code>, <code>setIgnoreTextBoxes(true)<\/code>, or <code>setMergePastedLists(true)<\/code>, then supply it to the method overload that accepts <code>ImportFormatOptions<\/code>. You can also adjust the resulting layout by modifying the destination section\u2019s <code>PageSetup<\/code> (e.g., <code>section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);<\/code>).<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Split a Document in Java","link":"https:\/\/docs.aspose.com\/words\/java\/split-a-document\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/split-a-document\/","description":"\n        \n        \n        <p><em>Splitting<\/em>\u00a0or\u00a0<em>split a document<\/em>\u00a0is the process of breaking a large document into a greater number of smaller files.\u00a0There are various reasons to split a file. For example, you only need some pages from a specific document and not the entire one. Or for privacy reasons, you want to share only some parts of a document with others.\u00a0With the splitting feature, you can get only the required parts of the document and do the necessary actions with them, for example, to mark up, save, or send.<\/p>\n<p>Aspose.Words provides you with an efficient way to split one document into multiple documents by headings or sections. You can also split a document by pages or by page ranges. Both splitting options will be described in this article.<\/p>\n<p>To split a document\u00a0into smaller files using Aspose.Words, you need to follow these steps:<\/p>\n<ol>\n<li>Load the document in any supported format.<\/li>\n<li>Split the\u00a0document.<\/li>\n<li>Save the output documents.<\/li>\n<\/ol>\n<p>After you split a document, you will be able to open all the output documents that will start with the required pages, text, etc.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\n<p><strong>Try online<\/strong><\/p>\n<p>You can try this functionality with our <a href=\"https:\/\/products.aspose.app\/words\/splitter\">Free online document splitter<\/a>.<\/p>\n\n<\/div>\n\n<h2 id=\"split-a-document-using-different-criteria\">Split a Document Using Different Criteria<\/h2>\n<p>Aspose.Words allows you to split EPUB or HTML documents into chapters according to various criteria.\u00a0In the process, the style and layout of the source document are preserved for the output documents.<\/p>\n<p>You can specify criteria using the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentsplitcriteria\/\">DocumentSplitCriteria<\/a>\u00a0enumeration. So you can divide a document into chapters using one of the following criteria or combine more than one criteria together:<\/p>\n<ul>\n<li>heading paragraph,<\/li>\n<li>section break,<\/li>\n<li>column break,<\/li>\n<li>page break.<\/li>\n<\/ul>\n<p>When saving the output to HTML, Aspose.Words save each individual chapter as a separate HTML file. As a result, the document will be split into multiple HTML files. When saving the output to EPUB, Aspose.Words save the result in a single EPUB file regardless of the <code>DocumentSplitCriteria<\/code> value you used.\u00a0So, using DocumentSplitCriteria for EPUB documents only affects the appearance of their content in reader applications: content will be divided into chapters and the document will no longer appear continuous.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou cannot split a document using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentsplitcriteria\/\">DocumentSplitCriteria<\/a> property when saving to MHTML format.\n<\/div>\n\n<p>In this section, we consider only some of the possible split criteria.<\/p>\n<h3 id=\"split-a-document-by-headings\">Split a Document by Headings<\/h3>\n<p>To split a document into chapters by headings, use the <strong>HeadingParagraph<\/strong> value of the <strong>DocumentSplitCriteria<\/strong> property.<\/p>\n<p>If you need to split a document by a specific level of heading paragraphs, such as headings 1, 2, and 3, use also the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/htmlsaveoptions\/#getDocumentSplitHeadingLevel\">DocumentSplitHeadingLevel<\/a> property. The output will be divided by paragraphs formatted with the specified heading level.<\/p>\n<p>The following code example shows how to split a document into smaller parts by heading:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertToHTML-SplitDocumentByHeadingsHTML.java\"><\/script>\n\n<p>Please note that for this criteria, Aspose.Words only supports saving to HTML format when splitting.<\/p>\n<p>When saving to EPUB, the document is not split into several files, and there will be only one output file.<\/p>\n<h3 id=\"split-a-document-by-sections\">Split a Document by Sections<\/h3>\n<p>Aspose.Words also enables you to use section breaks to split documents and save them to HTML. For this purpose, use\u00a0<strong>SectionBreak<\/strong> as the\u00a0<strong>DocumentSplitCriteria<\/strong>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-ConvertToHTML-SplitDocumentBySectionsHTML.java\"><\/script>\n\n<p>There is another way to split the source document into multiple output documents, and you can choose any output format supported by Aspose.Words.<\/p>\n<p>The following code example shows how to split\u00a0a document into smaller parts by section breaks (without using the <code>DocumentSplitCriteria<\/code> property):<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-SplitDocument-SplitDocumentBySections.java\"><\/script>\n\n<h2 id=\"splitting-by-pages\">Split by Pages<\/h2>\n<p>You can also split a document page by page, by page ranges, or starting with the specified page numbers. In such case the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#extractPages-int-int\">ExtractPages<\/a> method can do the job.<\/p>\n<p>This section describes several use cases of dividing documents by paged using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> class and the <strong>ExtractPages<\/strong> method.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can use any <a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/supported-document-formats\/\">output format supported by Aspose.Words<\/a>.\n<\/div>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nDue to the many nuances appearing while reducing the number of pages, a full match with the Microsoft Word layout is quite a complicated task. Therefore, depending on the document complexity, there may be slight differences in the resulting document layout from the original document.\n<\/div>\n\n<h3 id=\"split-a-document-page-by-page\">Split a Document Page by Page<\/h3>\n<p>Aspose.Words enables you to split a multi-page document page by page.<\/p>\n<p>The following code example shows how to\u00a0divide a document and\u00a0save each page as a separate document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-SplitDocument-SplitDocumentPageByPage.java\"><\/script>\n\n<h3 id=\"split-a-document-by-page-ranges\">Split a Document by Page Ranges<\/h3>\n<p>Aspose.Words allows splitting a multi-page document by page ranges. You can split one file into multiple files with various page ranges or just select one range and save only this part of the source document.\u00a0Note that you can choose the page range according to the maximum and minimum page number of a document.<\/p>\n<p>The following code example shows how to split a document into smaller parts by page range with specific start and end indexes:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-SplitDocument-SplitDocumentByPageRange.java\"><\/script>\n\n<h2 id=\"callback-option-for-saving-a-document\">Callback Option to Save a Document<\/h2>\n<p>You can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/htmlsaveoptions\/#getDocumentPartSavingCallback\">DocumentPartSavingCallback<\/a> property to control how\u00a0Aspose.Words saves document parts when this document is exported into\u00a0HTML format. This property allows you to rename output files or even to redirect them into custom streams.<\/p>\n<p>Please note that this callback is not useful when saving to EPUB because all output parts must be saved into a single container \u2013 the .epub file. So, stream redirection is not supported, and the effect of renaming is not visible since files are renamed inside the container.<\/p>\n<h2 id=\"merge-the-split-document-with-another-file\">Merge the Split Document with Another Document<\/h2>\n<p>Aspose.Words enables you to merge the\u00a0output split\u00a0document with another\u00a0document\u00a0to form a new\u00a0document.\u00a0This can be called document merging.<\/p>\n<p>The following code example shows how to merge a split document with another document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-SplitDocument-MergeDocuments.java\"><\/script>\n\n\n      "},{"title":"Java: Find and Replace in Java","link":"https:\/\/docs.aspose.com\/words\/java\/find-and-replace\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/find-and-replace\/","description":"\n        \n        \n        <p>You can easily navigate within your document using a keyboard and mouse, but if you have many pages to scroll through, it will take quite a while to find specific text in a long document. It will be more time consuming when you want to replace certain characters or words that you have used in your document. The \u201cFind and replace\u201d functionality enables you to find a sequence of characters in a document and replace it with another sequence of characters.<\/p>\n<p>Aspose.Words allows you to find a specific string or regular expression pattern in your document and replace it with an alternative without installing and using additional applications such as Microsoft Word. This will speed up many typing and formatting tasks, potentially saving you hours of work.<\/p>\n<p>This article explains how to apply string replacement and regular expressions with the support of metacharacters.<\/p>\n<h2 id=\"ways-to-find-and-replace\">Ways to Find and Replace<\/h2>\n<p>Aspose.Words provides two ways to apply the find and replace operation by using the following:<\/p>\n<ol>\n<li><em>Simple string replacement<\/em> \u2013 to find and replace a specific string with another, you need to specify a search string (alphanumeric characters) that is going to be replaced according to all occurrences with another specified replacement string. Both strings must not contain symbols. Take into account that string comparison can be case-sensitive, or you may be unsure of spelling or have several similar spellings.<\/li>\n<li><em>Regular expressions<\/em> \u2013 to specify a regular expression to find the exact string matches and replace them according to your regular expression. Note that a word is defined as being made up of only alphanumeric characters. If a replacement is executed with only whole words being matched and the input string happens to contain symbols, then no phrases will be found.<\/li>\n<\/ol>\n<p>Also, you can use special metacharacters with simple string replacement and regular expressions to specify breaks within the find and replace operation.<\/p>\n<p>Aspose.Words presents the find and replace functionality with the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/ireplacingcallback\/\">IReplacingCallBack<\/a>. You can work with many options during the find and replace process using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/\">FindReplaceOptions<\/a> class.<\/p>\n<h3 id=\"find-and-replace-text-using-simple-string-replacement\">Find and Replace Text Using Simple String Replacement<\/h3>\n<p>You can use one of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/range\/#replace-java.lang.String-java.lang.String\">Replace<\/a> methods to find or replace a particular string and return the number of replacements that were made. In this case, you can specify a string to be replaced, a string that will replace all its occurrences, whether the replacement is case-sensitive, and whether only stand-alone words will be affected.<\/p>\n<p>The following code example shows how to find the string \u201c<em>CustomerName<\/em>\u201d and replace it with the string <em>\u201cJames Bond\u201d<\/em>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-SimpleStringReplacement.java\"><\/script>\n\n<p>You can notice the difference between the document before applying simple string replacement:<\/p>\n<img src=\"before-simple-string-replacement.png\" alt=\"before-simple-string-replacement-aspose-words-java\" style=\"width:600px\"\/>\n<p>And after applying simple string replacement:<\/p>\n<img src=\"after-simple-string-replacement.png\" alt=\"after-simple-string-replacement-aspose-words-java\" style=\"width:600px\"\/>\n<h3 id=\"find-and-replace-text-using-regular-expressions\">Find and Replace Text Using Regular Expressions<\/h3>\n<p>A regular expression (regex) is a pattern that describes a certain sequence of text. Suppose you want to replace all double occurrences of a word with a single word occurrence. Then you can apply the following regular expression to specify the double-word pattern: <code>([a-zA-Z]+) \\1<\/code>.<\/p>\n<p>Use the other <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/range\/#replace-java.util.regex.Pattern-java.lang.String\">Replace<\/a> method to search and replace particular character combinations by setting the <code>Regex<\/code> parameter as the regular expression pattern to find matches.<\/p>\n<p>The following code example shows how to replace strings that match a regular expression pattern with a specified replacement string:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-UsingRegularExpression.java\"><\/script>\n\n<p>You can notice the difference between the document before applying string replacement with regular expressions:<\/p>\n<img src=\"before-replacement-with-regular-expressions.png\" alt=\"before-replacement-with-regular-expressions-aspose-words-java\" style=\"width:600px\"\/>\n<p>And after applying string replacement with regular expressions:<\/p>\n<img src=\"after-replacement-with-regular-expressions.png\" alt=\"after-replacement-with-regular-expressions-aspose-words-java\" style=\"width:600px\"\/>\n<h3 id=\"find-and-replace-text-using-metacharacters\">Find and Replace String Using Metacharacters<\/h3>\n<p>You can use metacharacters in the search string or the replacement string if a particular text or phrase is composed of multiple paragraphs, sections, or pages. Some of the metacharacters include <strong>&amp;p<\/strong> for a paragraph break, <strong>&amp;b<\/strong> for a section break, <strong>&amp;m<\/strong> for a page break, and <strong>&amp;l<\/strong> for a line break.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the metacharacter <strong>&amp;&amp;<\/strong> equals to <strong>&amp;<\/strong>. For example, if you need to find the text for <strong>&amp;p<\/strong> that is not a paragraph break, then you can use <strong>&amp;&amp;p<\/strong>.\n<\/div>\n\n<p>The following code example shows how to replace text with paragraph and page break:\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-ReplaceTextContaingMetaCharacters.java\"><\/script>\n<\/p>\n<h2 id=\"find-and-replace-string-in-header-or-footer-of-a-document\">Find and Replace String in Header\/Footer of a Document<\/h2>\n<p>You can find and replace text in the header\/footer section of a Word document using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/headerfooter\/\">HeaderFooter<\/a> class.<\/p>\n<p>The following code example shows how to replace the text of the header section in your document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-ReplaceTextInHeader.java\"><\/script>\n\n<p>You can notice the difference between the document before applying header string replacement:<\/p>\n<img src=\"before-applying-header-string-replacement.png\" alt=\"before-applying-header-string-replacement-aspose-words-java\" style=\"width:600px\"\/>\n<p>And after applying header string replacement:<\/p>\n<img src=\"after-applying-header-string-replacement.png\" alt=\"after-applying-header-string-replacement-aspose-words-java\" style=\"width:600px\"\/>\n<p>The code example to replace the text of the footer section in your document is very similar to the previous header code example. All you need to do is replace the following two lines:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"n\">HeaderFooter<\/span> <span class=\"n\">header<\/span> <span class=\"o\">=<\/span> <span class=\"n\">headersFooters<\/span><span class=\"o\">.<\/span><span class=\"na\">get<\/span><span class=\"o\">(<\/span><span class=\"n\">HeaderFooterType<\/span><span class=\"o\">.<\/span><span class=\"na\">HEADER_PRIMARY<\/span><span class=\"o\">);<\/span>\n<span class=\"n\">header<\/span><span class=\"o\">.<\/span><span class=\"na\">getRange<\/span><span class=\"o\">().<\/span><span class=\"na\">replace<\/span><span class=\"o\">(<\/span><span class=\"s\">&#34;Aspose.Words&#34;<\/span><span class=\"o\">,<\/span> <span class=\"s\">&#34;Remove&#34;<\/span><span class=\"o\">,<\/span> <span class=\"n\">options<\/span><span class=\"o\">);<\/span><\/code><\/pre><\/div>\n<p>With the following:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-ReplaceTextInFooter.java\"><\/script>\n\n<p>You can notice the difference between the document before applying footer string replacement:<\/p>\n<img src=\"before-applying-footer-string-replacement.png\" alt=\"before-applying-footer-string-replacement-aspose-words-java\" style=\"width:600px\"\/>\n<p>And after applying footer string replacement:<\/p>\n<img src=\"after-applying-footer-string-replacement.png\" alt=\"after-applying-footer-string-replacement-aspose-words-java\" style=\"width:600px\"\/>\n<h2 id=\"ignore-text-during-find-and-replace\">Ignore Text During Find and Replace<\/h2>\n<p>While applying the find and replace operation, you can ignore certain segments of the text. So, certain parts of the text can be excluded from the search, and the find and replace can be applied only to the remaining parts.<\/p>\n<p>Aspose.Words provides many find and replace properties for ignoring text such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getIgnoreDeleted\">IgnoreDeleted<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getIgnoreFieldCodes\">IgnoreFieldCodes<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getIgnoreFields\">IgnoreFields<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getIgnoreFootnotes\">IgnoreFootnotes<\/a>, and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getIgnoreInserted\">IgnoreInserted<\/a>.<\/p>\n<p>The following code example shows how to ignore text inside delete revisions:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-IgnoreText-IgnoreTextInsideDeleteRevisions.java\"><\/script>\n\n<h2 id=\"customize-find-and-replace-operation\">Customize Find and Replace Operation<\/h2>\n<p>Aspose.Words provides many different <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/\">properties<\/a> to find and replace text such as applying specific format with <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getApplyFont\">ApplyFont<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getApplyParagraphFormat\">ApplyParagraphFormats<\/a> properties, using substitutions in replacement patterns with <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/findreplaceoptions\/#getUseSubstitutions\">UseSubstitutions<\/a> property, and others.<\/p>\n<p>The following code example shows how to highlight a specific word in your document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-CustomizeFindAndReplaceOperation.java\"><\/script>\n\n<p>Aspose.Words allows you to use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/ireplacingcallback\/\">IReplacingCallback<\/a> interface to create and call a custom method during a replace operation. You may have some use cases where you need to customize the find and replace operation such as replacing text specified with a regular expression with HTML tags, so basically you will apply replace with inserting HTML.<\/p>\n<p>If you need to replace a string with an HTML tag, apply the <strong>IReplacingCallback<\/strong> interface to customize the find and replace operation so the match starts at the beginning of a run with the match node of your document. Let us provide several examples of using <strong>IReplacingCallback<\/strong>.<\/p>\n<p>The following code example shows how to replace text specified with HTML:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-ReplaceWithHtml.java\"><\/script>\n\n<p>The following code example shows how to highlight positive numbers with green color and negative numbers with red color:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-NumberHighlightCallback.java\"><\/script>\n\n<p>The following code example shows how to prepend a line number to each line:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-find_replace-FindAndReplace-TestLineCounter.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I replace text with HTML markup while preserving the document\u2019s formatting?<br>\n<strong>A:<\/strong> Implement the <code>IReplacingCallback<\/code> interface and, in the <code>replacing<\/code> method, insert the HTML using <code>DocumentBuilder.insertHtml<\/code>. Set <code>FindReplaceOptions.setReplacingCallback<\/code> to your callback instance, then call <code>Range.replace<\/code> with a regex that matches the placeholder.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What is the easiest way to replace a merge field without affecting its surrounding runs?<br>\n<strong>A:<\/strong> Use <code>Range.replace<\/code> with the exact merge\u2011field name (e.g., <code>&quot;\u00abCustomerName\u00bb&quot;<\/code>) and set <code>FindReplaceOptions.setMatchWholeWord(true)<\/code>. This replaces the whole field node, leaving other runs untouched.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I ignore text inside deleted revisions or footnotes during a replace operation?<br>\n<strong>A:<\/strong> Configure <code>FindReplaceOptions<\/code> by enabling <code>setIgnoreDeleted(true)<\/code> and\/or <code>setIgnoreFootnotes(true)<\/code>. Pass the options to <code>Range.replace<\/code> and the engine will skip those nodes.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I use metacharacters to insert line or page breaks in the replacement string?<br>\n<strong>A:<\/strong> Yes. Include <code>&amp;l<\/code> for a line break, <code>&amp;p<\/code> for a paragraph break, <code>&amp;m<\/code> for a page break, or <code>&amp;b<\/code> for a section break in the replacement text. Escape an ampersand with <code>&amp;&amp;<\/code> if you need a literal <code>&amp;<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I replace text only in headers or footers without affecting the main body?<br>\n<strong>A:<\/strong> Iterate through each <code>HeaderFooter<\/code> via <code>Document.getFirstSection().getHeadersFooters()<\/code>, then call <code>headerFooter.getRange().replace(search, replace, options)<\/code> on the header\/footer range only. This isolates the operation to those parts.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Styles and Themes","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-styles-and-themes\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-styles-and-themes\/","description":"\n        \n        \n        <p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/stylecollection\/\">StyleCollection<\/a> class is used to manage built-in and apply user-defined settings to styles.<\/p>\n<h2 id=\"how-to-extract-content-based-on-styles\">How to Extract Content Based on Styles<\/h2>\n<p>At a simple level, retrieving the content based on styles from a Word document can be useful to identify, list and count paragraphs and runs of text formatted with a specific style. For example, you may need to identify particular kinds of content in the document, such as examples, titles, references, keywords, figure names, and case studies.<\/p>\n<p>To take this a few steps further, this can also be used to leverage the structure of the document, defined by the styles it uses, to re-purpose the document for another output, such as HTML. This is in fact how the Aspose documentation is built, putting Aspose.Words to the test. A tool built using Aspose.Words takes the source Word documents and splits them into topics at certain heading levels. An XML file is produced using Aspose.Words which is used to build the navigation tree you can see on the left. And then Aspose.Words converts each topic into HTML.\u00a0The solution for retrieving text formatted with specific styles in a Word document is typically economical and straightforward using Aspose.Words.<\/p>\n<p>To illustrate how easily Aspose.Words handles retrieving content based on styles, let\u2019s look at an example. In this example, we\u2019re going to retrieve text formatted with a specific paragraph style and a character style from a sample Word document.<\/p>\n<p>At a high level, this will involve:<\/p>\n<ol>\n<li>Opening a Word document using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> class.<\/li>\n<li>Getting collections of all paragraphs and all runs in the document.<\/li>\n<li>Selecting only the required paragraphs and runs.<\/li>\n<\/ol>\n<p>Specifically, we\u2019ll retrieve text formatted with the \u2018Heading 1\u2019 paragraph style and the \u2018Intense Emphasis\u2019 character style from this sample Word document.<\/p>\n<p><img src=\"working-with-styles-1.png\" alt=\"working-with-styles-aspose-words-java-1\"><\/p>\n<p>In this sample document, the text formatted with the \u2018Heading 1\u2019 paragraph style is \u2018Insert Tab\u2019, \u2018Quick Styles\u2019 and \u2018Theme\u2019, and the text formatted with the \u2018Intense emphasis\u2019 character style is the several instances of blue, italicized, bold text such as \u2018galleries\u2019 and \u2018overall look\u2019.<\/p>\n<p>The implementation of a style-based query is quite simple in the Aspose.Words document object model, as it simply uses tools that are already in place.\u00a0Two class methods are implemented for this solution:<\/p>\n<ol>\n<li><strong>ParagraphsByStyleName<\/strong> \u2013 This method retrieves an array of those paragraphs in the document that have a specific style name.<\/li>\n<li><strong>RunsByStyleName<\/strong> \u2013 This method retrieves an array of those runs in the document that have a specific style name.<\/li>\n<\/ol>\n<p>Both these methods are very similar, the only differences being the node types and the representation of the style information within the paragraph and run nodes.\u00a0Here is an implementation of ParagraphsByStyleName shown in the code example given below to find all paragraphs formatted with the specified style.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-styles-ExtractContentBasedOnStyles-paragraphsByStyleName.java\"><\/script>\n\n<p>This implementation also uses the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getChildNodes\">Document.getChildNodes()<\/a> method of the <code>Document<\/code> class, which returns a collection of all immediate child nodes.<\/p>\n<p>It\u2019s also worth pointing out that the paragraphs collection does not create an immediate overhead because paragraphs are loaded into this collection only when you access items in them.Then, all you need to do is to go through the collection, using the standard foreach operator and add paragraphs that have the specified style to the paragraphsWithStyle array. The <code>Paragraph<\/code> style name can be found in the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/style\/#getName\">Style.getName()<\/a> property of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/style\/#getParagraphFormat\">Paragraph.getParagraphFormat()<\/a> object.<\/p>\n<p>The implementation of RunsByStyleName is almost the same, although we\u2019re obviously using <code>NodeType.Run<\/code> to retrieve run nodes. The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/#getStyle\">Font.getStyle()<\/a> property of a <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/run\/\">Run<\/a> object is used to access style information in the <strong>Run<\/strong> nodes.\u00a0<\/p>\n<p>The following code example finds all runs formatted with the specified style.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-styles-ExtractContentBasedOnStyles-runsByStyleName.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nWhen both queries are implemented, all you need to do is to pass a document object and specify the style names of the content you want to retrieve:\n<\/div>\n\n<p>The following code example run queries and display results.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-styles-ExtractContentBasedOnStyles-ExtractContentBasedOnStyles.java\"><\/script>\n\n<p>When everything is done, running the sample will display the following output:<\/p>\n<p><img src=\"working-with-styles-2.png\" alt=\"working-with-styles-aspose-words-java-2\"><\/p>\n<p>As you can see, this is a very simple example, showing the number and text of the collected paragraphs and runs in the sample Word document.<\/p>\n<h2 id=\"insert-style-separator-to-put-different-paragraph-styles\">Insert Style Separator to Put Different Paragraph Styles<\/h2>\n<p>The style separator can be added to the end of a paragraph using the Ctrl + Alt + Enter Keyboard Shortcut into MS Word. This feature allows for two different paragraph styles used in one logical printed paragraph.\u00a0If you want some text from the beginning of a particular heading to appear in a Table of Contents but do not want the entire heading in the Table of Contents, you can use this feature.<\/p>\n<p>The following code example shows how to insert a style separator to put different paragraph styles.\u00a0<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-ParagraphInsertStyleSeparator.java\"><\/script>\n\n<h2 id=\"copy-all-styles-from-template\">Copy All Styles from Template<\/h2>\n<p>There are cases when you want to copy all styles from one document into another. You can use the <code>Document.CopyStylesFromTemplate<\/code> method to copy styles from the specified template to a document. When styles are copied from a template to a document, like-named styles in the document are redefined to match the style descriptions in the template. Unique styles from the template are copied to the document. Unique styles in the document remain intact.<\/p>\n<p>The following code example shows how to copy styles from one document into another.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithStyle-CopyStylesFromDocument.java\"><\/script>\n\n<h2 id=\"how-to-manipulate-theme-properties\">How to Manipulate Theme Properties<\/h2>\n<p>We have added basic API in Aspose.Words to access document theme properties. For now, this API includes the following public objects:<\/p>\n<ul>\n<li>Theme<\/li>\n<li>ThemeFonts<\/li>\n<li>ThemeColors<\/li>\n<\/ul>\n<p>Here is how you can get theme properties:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Theme-GetThemeProperties-GetThemeProperties.java\"><\/script>\n\n<p>And here is how you can set theme properties:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Theme-SetThemeProperties-SetThemeProperties.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I retrieve all paragraphs that use a specific style?<br>\n<strong>A:<\/strong> Use <code>Document.getChildNodes(NodeType.PARAGRAPH, true)<\/code> to obtain all paragraphs, then filter them by checking <code>paragraph.getParagraphFormat().getStyle().getName()<\/code> against the desired style name. The helper method <code>ParagraphsByStyleName<\/code> in the article demonstrates this approach.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I get all runs (character formatting) that have a particular style?<br>\n<strong>A:<\/strong> Call <code>Document.getChildNodes(NodeType.RUN, true)<\/code> to collect all runs, and filter with <code>run.getFont().getStyle().getName()<\/code>. The <code>RunsByStyleName<\/code> method in the article provides a ready\u2011to\u2011use example.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I insert a style separator so that a single line contains two different paragraph styles?<br>\n<strong>A:<\/strong> Insert a <code>StyleSeparator<\/code> node at the desired position inside a paragraph. In Java you can create it with <code>StyleSeparator separator = new StyleSeparator(document); paragraph.appendChild(separator);<\/code> and then add the second run with the alternate style after the separator.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I copy all styles from a template document into another document?<br>\n<strong>A:<\/strong> Load the template with <code>Document template = new Document(&quot;Template.docx&quot;);<\/code> and the target document with <code>Document target = new Document(&quot;Target.docx&quot;);<\/code>. Then call <code>target.copyStylesFromTemplate(template);<\/code>. This copies matching styles and adds any unique styles from the template.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I read or modify the theme colors, fonts, or other theme properties of a document?<br>\n<strong>A:<\/strong> Access the theme via <code>Theme theme = document.getTheme();<\/code>. You can read colors with <code>theme.getColors().getAccent1()<\/code> and fonts with <code>theme.getFonts().getMajor()<\/code>. To change a property, assign a new value, e.g., <code>theme.getColors().setAccent1(Color.getBlue());<\/code> and then save the document. The code snippets in the \u201cHow to Manipulate Theme Properties\u201d section illustrate both reading and setting these values.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Sections in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-sections\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-sections\/","description":"\n        \n        \n        <p>Sometimes you want a document that does not have the same formatting across all pages. For example, you may need to modify page number formats, have different page size and orientation, or have the first document page as a cover page without any numbering. You can achieve that with sections.<\/p>\n<p>Sections are level nodes that control headers and footers, orientation, columns, margins, page number formatting, and others.<\/p>\n<p>Aspose.Words allows you to manage sections, divide a document into sections, and make formatting changes that apply only to a specific section. Aspose.Words stores information about section formatting such as headers and footers, page setup, and column settings in the section break.<\/p>\n<p>This article explains how to work with sections and section breaks.<\/p>\n<h2 id=\"what-section-and-section-break-is\">What Section and Section Break Is<\/h2>\n<p>Document sections are represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/\">Section<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/sectioncollection\/\">SectionCollection<\/a> classes. Section objects are immediate children of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> node and can be accessed via the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getSections\">Sections<\/a> property. You can manage those nodes by using some methods such as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/nodecollection\/#remove-com.aspose.words.Node\">Remove<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/nodecollection\/#add-com.aspose.words.Node\">Add<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/nodecollection\/#indexOf-com.aspose.words.Node\">IndexOf<\/a>, and others.<\/p>\n<p>Section break is an option that divides document pages into sections with customizable layouts.<\/p>\n<h2 id=\"types-of-a-section-break\">Types of a Section Break<\/h2>\n<p>Aspose.Words allows you to split and format documents using different section breaks of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/breaktype\/\">BreakType<\/a> enumeration:<\/p>\n<ul>\n<li>SectionBreakContinuous<\/li>\n<li>SectionBreakNewColumn<\/li>\n<li>SectionBreakNewPage<\/li>\n<li>SectionBreakEvenPage<\/li>\n<li>SectionBreakOddPage<\/li>\n<\/ul>\n<p>You can also use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/sectionstart\/\">SectionStart<\/a> enumeration to choose a break type that applies only for the first section such as NewColumn, NewPage, EvenPage, and OddPage.<\/p>\n<h2 id=\"manage-a-section\">Manage a Section<\/h2>\n<p>Since a section is a normal composite node, the entire node manipulation API can be used to manipulate sections: to add, remove, and other operations on sections. You can read more about nodes in the article <a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/aspose-words-document-object-model\/\">Aspose.Words Document Object Model (DOM)<\/a>.<\/p>\n<p>On the other hand, you can also use the <code>DocumentBuilder<\/code> API to work with sections. In this article, we will focus on this particular way of working with sections.<\/p>\n<h2 id=\"insert-or-remove-a-section-break\">Insert or Remove a Section Break<\/h2>\n<p>Aspose.Words allows you to insert a section break into text using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertBreak-int\">InsertBreak<\/a> method.<\/p>\n<p>The following code example shows how to insert a section break into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=insert-section-breaks.java\"><\/script>\n\n<p>Use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#remove\">Remove<\/a> method to delete a section break. If you do not need to remove a specific section break and instead delete the content of that section, you can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/#clearContent\">ClearContent<\/a> method.<\/p>\n<p>The following code example shows how to remove sections breaks:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=remove-section-breaks.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that a section break has information about the section that goes before it, not the section that goes after it. So if you remove a section break, the text before the removed break will get the properties of the section break following it. This can cause the entire document to becoming landscape, or headers and footers to change or fully disappear.\n<\/div>\n\n<h2 id=\"move-a-section\">Move a Section<\/h2>\n<p>If you want to move a section from one position to another in your document, you need to get the index of that section. Aspose.Words allows you to get a section position from a <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/sectioncollection\/\">SectionCollection<\/a>. You can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getSections\">Sections<\/a> property to get all sections in your document. But if you want to get only the first section, you can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getFirstSection\">FirstSection<\/a> property.<\/p>\n<p>The following code example shows how to access the first section and iterate through the children of a composite node:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=section-child-nodes.java\"><\/script>\n\n<h2 id=\"specify-a-section-layout\">Specify a Section Layout<\/h2>\n<p>Sometimes you want your document to look better by making creative layouts for different document sections. If you want to specify the type of the current section grid, you can choose a section layout mode using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/sectionlayoutmode\/\">SectionLayoutMode<\/a> enumeration:<\/p>\n<ul>\n<li>Default<\/li>\n<li>Grid<\/li>\n<li>LineGrid<\/li>\n<li>SnapToChars<\/li>\n<\/ul>\n<p>The following code example shows how to limit the number of lines that each page may have:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=line-grid-section-layout-mode.java\"><\/script>\n\n<h2 id=\"edit-a-section\">Edit a Section<\/h2>\n<p>When you add a new section to your document, there will be no body or paragraph that you can edit. Aspose.Words allows you to guarantee that a section contains a body with at least one paragraph using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/#ensureMinimum\">EnsureMinimum<\/a> method \u2013 it will automatically add a Body (or HeaderFooter) node to the document and then add a Paragraph to it.<\/p>\n<p>The following code example shows how to prepare a new section node using <strong>EnsureMinimum<\/strong>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=ensure-minimum.java\"><\/script>\n\n<h3 id=\"append-or-prepend-content\">Append or Prepend Content<\/h3>\n<p>If you want to draw some shape or add text or image at the beginning\/end of a section, you can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/#appendContent-com.aspose.words.Section\">AppendContent<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/#prependContent-com.aspose.words.Section\">PrependContent<\/a> methods of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/\">Section<\/a> class.<\/p>\n<p>The following code example shows how to append content of an existing section:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=append-section-content.java\"><\/script>\n\n<h3 id=\"clone-a-section\">Clone a Section<\/h3>\n<p>Aspose.Words allows you to duplicate a section by creating a full copy of it using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/#deepClone\">deepClone<\/a> method.<\/p>\n<p>The following code example shows how to clone the first section in your document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=clone-section.java\"><\/script>\n\n<h3 id=\"copy-sections-between-documents\">Copy Sections between Documents<\/h3>\n<p>In some cases, you may have large documents with many sections and you want to copy the content of a section from one document to another.<\/p>\n<p>Aspose.Words allows you to copy sections between documents using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbase\/#importNode-com.aspose.words.Node-boolean\">ImportNode<\/a> method.<\/p>\n<p>The following code example shows how to copy sections between documents:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=copy-section.java\"><\/script>\n\n<h3 id=\"work-with-section-header-and-footer\">Work with Section Header and Footer<\/h3>\n<p>The basic rules for displaying a header or footer for each section are quite simple:<\/p>\n<ol>\n<li>If the section does not have its own headers\/footers of a certain type, then it is taken from the previous section.<\/li>\n<li>The type of header\/footer displayed on the page is controlled by the &ldquo;Different First Page&rdquo; and &ldquo;Different Odd &amp; Even pages&rdquo; section settings \u2013 if they are disabled, then the section&rsquo;s own titles are ignored.<\/li>\n<\/ol>\n<p>The following code example shows how to create 2 sections with different headers:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=link-to-previous-header-footer.java\"><\/script>\n\n<p>If you want to remove the text of headers and footers without removing <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/headerfooter\/\">HeaderFooter<\/a> objects in your document, you can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/#clearHeadersFooters\">ClearHeadersFooters<\/a> method. In addition, you can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/section\/#deleteHeaderFooterShapes\">DeleteHeaderFooterShapes<\/a> method to remove all shapes from headers and footers in your document.<\/p>\n<p>The following code example shows how to clear content of all headers and footers in a section:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=delete-header-footer-content.java\"><\/script>\n\n<p>The following code example how to remove all shapes from all headers footers in a section:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=delete-header-footer-shapes.java\"><\/script>\n\n<h2 id=\"customize-page-properties-in-a-section\">Customize Page Properties in a Section<\/h2>\n<p>Before printing a page or a document you may want to customize and modify the size and layout of a single page or the whole document. With page setup, you can change the settings of document pages such as margins, orientation, and size for printing different first pages or odd pages.<\/p>\n<p>Aspose.Words allows you to customize page and section properties using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/\">PageSetup<\/a> class.<\/p>\n<p>The following code example shows how to set such properties as page size and orientation for the current section:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=page-setup-and-section-formatting.java\"><\/script>\n\n<p>The following code example shows how to modify the page properties in all sections:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/7c0668453e53ed7a57d3ea3a05520f21.js?file=modify-page-setup-in-all-sections.java\"><\/script>\n\n<h2 id=\"see-also\">See Also<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/logical-levels-of-nodes-in-a-document\/\">Logical Levels of Nodes in a Document<\/a><\/li>\n<li><a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/insert-and-append-documents\/\">Insert and Append Documents<\/a><\/li>\n<\/ul>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p>Q: How can I insert a section break at a specific location in a Java document?<br>\nA: Use <code>DocumentBuilder.insertBreak(BreakType.SectionBreakNewPage)<\/code> (or another <code>BreakType<\/code>) at the desired cursor position. Create a <code>DocumentBuilder<\/code> for the document, move the cursor to the target node, then call <code>insertBreak<\/code>.<\/p>\n<\/li>\n<li>\n<p>Q: What is the safest way to remove a section break without losing the formatting of surrounding sections?<br>\nA: Locate the <code>Section<\/code> node that contains the break, then call <code>section.getPreviousSibling().remove()<\/code> or remove the <code>Section<\/code> node itself using <code>section.remove()<\/code>. After removal, the content before the break inherits the formatting of the following section, so you may need to copy the required <code>PageSetup<\/code> settings before removal.<\/p>\n<\/li>\n<li>\n<p>Q: How do I clone a section and insert the clone into the same document or another document?<br>\nA: Call <code>Section clonedSection = (Section) originalSection.deepClone();<\/code> and then add it to the target document\u2019s <code>Sections<\/code> collection with <code>targetDoc.getSections().add(clonedSection);<\/code>. If the target document is different, import the cloned node first using <code>targetDoc.importNode(clonedSection, true)<\/code>.<\/p>\n<\/li>\n<li>\n<p>Q: How can I set different headers or footers for the first page and for odd\/even pages within a section?<br>\nA: Access the <code>Section<\/code> object and set <code>section.getPageSetup().setDifferentFirstPageHeaderFooter(true);<\/code> and <code>section.getPageSetup().setOddAndEvenPagesHeaderFooter(true);<\/code>. Then create or modify the <code>HeaderFooter<\/code> objects for <code>HeaderFooterType.HEADER_FIRST<\/code>, <code>HEADER_EVEN<\/code>, and <code>HEADER_PRIMARY<\/code> as needed.<\/p>\n<\/li>\n<li>\n<p>Q: How can I change the page size and orientation for only one section?<br>\nA: Retrieve the <code>Section<\/code> you want to modify and use its <code>PageSetup<\/code> property:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"n\">Section<\/span> <span class=\"n\">section<\/span> <span class=\"o\">=<\/span> <span class=\"n\">doc<\/span><span class=\"o\">.<\/span><span class=\"na\">getSections<\/span><span class=\"o\">().<\/span><span class=\"na\">get<\/span><span class=\"o\">(<\/span><span class=\"n\">2<\/span><span class=\"o\">);<\/span> <span class=\"c1\">\/\/ example index\n<\/span><span class=\"c1\"><\/span><span class=\"n\">PageSetup<\/span> <span class=\"n\">setup<\/span> <span class=\"o\">=<\/span> <span class=\"n\">section<\/span><span class=\"o\">.<\/span><span class=\"na\">getPageSetup<\/span><span class=\"o\">();<\/span>\n<span class=\"n\">setup<\/span><span class=\"o\">.<\/span><span class=\"na\">setPaperSize<\/span><span class=\"o\">(<\/span><span class=\"n\">PaperSize<\/span><span class=\"o\">.<\/span><span class=\"na\">A4<\/span><span class=\"o\">);<\/span>\n<span class=\"n\">setup<\/span><span class=\"o\">.<\/span><span class=\"na\">setOrientation<\/span><span class=\"o\">(<\/span><span class=\"n\">Orientation<\/span><span class=\"o\">.<\/span><span class=\"na\">LANDSCAPE<\/span><span class=\"o\">);<\/span>\n<\/code><\/pre><\/div><p>This affects only the selected section, leaving other sections unchanged.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Ranges in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-ranges\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-ranges\/","description":"\n        \n        \n        \n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nIn Aspose.Words, a Range is a \u201cflat window\u201d into an otherwise tree-like model of the document.\n<\/div>\n\n<p>If you have worked with Microsoft Word Automation, you probably know that one of the main tools to examine and modify document content is the <code>Range<\/code> object.Range is like a &ldquo;window&rdquo; into the document content and formatting.<\/p>\n<p>Aspose.Words also has the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/range\/\">Range<\/a> class and it is designed to look and act similarly to <strong>Range<\/strong> in Microsoft Word. Although <strong>Range<\/strong> cannot cover an arbitrary portion of a document and does not have a <strong>Start<\/strong> and <strong>End<\/strong>, you can access the range covered by any document node including the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> itself. In other words, each node has its own range.\u00a0The <strong>Range<\/strong> object allows you to access and modify text, bookmarks and form fields within the range.<\/p>\n<h2 id=\"retrieving-plain-text\">Retrieving Plain Text<\/h2>\n<p>Use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/range\/#getText\">Text<\/a> property to retrieve the plain, unformatted text of the range.<\/p>\n<p>The following code example shows how to get a plain, unformatted text of a range:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Ranges-RangesGetText-RangesGetText.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Document.doc\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<h2 id=\"delete-text\">Delete Text<\/h2>\n<p>The <code>Range<\/code> class allows the deletion of all characters of the range by calling <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/range\/#delete\">delete<\/a>.<\/p>\n<p>The following code example shows how to delete all characters of a range:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Ranges-RangesDeleteText-RangesDeleteText.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Document.doc\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<h2 id=\"heading\"><\/h2>\n\n      "},{"title":"Java: Extract Selected Content Between Nodes in Java","link":"https:\/\/docs.aspose.com\/words\/java\/extract-selected-content-between-nodes\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/extract-selected-content-between-nodes\/","description":"\n        \n        \n        <p>When working with documents, it is important to be able to easily extract content from a specific range within a document. However, the content may consist of complex elements such as paragraphs, tables, images, etc.<\/p>\n<p>Regardless of what content needs to be extracted, the method to extract that content will always be determined by which nodes are selected to extract content between. These can be entire text bodies or simple text runs.<\/p>\n<p>There are many possible situations and therefore many different node types to consider when extracting content. For example, you might want to extract content between:<\/p>\n<ul>\n<li>Two specific paragraphs<\/li>\n<li>Specific runs of text<\/li>\n<li>Fields of various types, such as merge fields<\/li>\n<li>Start and end ranges of a bookmark or comment<\/li>\n<li>Various bodies of text contained in separate sections<\/li>\n<\/ul>\n<p>In some situations, you may even need to combine different node types, such as extracting content between a paragraph and a field, or between a run and a bookmark.<\/p>\n<p>This article provides the code implementation for extracting text between different nodes, as well as examples of common scenarios.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nThese examples are just a few demonstrations of the many possibilities. We plan for the text extraction functionality to be part of the public API in the future, and no extra code will be required. In the meantime, feel free to post your requests regarding this functionality on the <a href=\"https:\/\/forum.aspose.com\/c\/words\/8\">Aspose.Words forum<\/a>.\n<\/div>\n\n<h2 id=\"why-extract-content\">Why Extract Content<\/h2>\n<p>Often the goal of extracting the content is to duplicate or save it separately in a new document. For example, you can extract content and:<\/p>\n<ul>\n<li>Copy it into a separate document<\/li>\n<li>Convert a specific part of a document to PDF or image<\/li>\n<li>Duplicate the content in the document many times<\/li>\n<li>Work with extracted content separate from the rest of the document<\/li>\n<\/ul>\n<p>This can be easily achieved using Aspose.Words and the code implementation below.<\/p>\n<h2 id=\"extracting-content-algorithm\">Extracting Content Algorithm<\/h2>\n<p>The code in this section addresses all of the possible situations described above with one generalized and reusable method. The general outline of this technique involves:<\/p>\n<ol>\n<li>Gathering the nodes which dictate the area of content that will be extracted from your document. Retrieving these nodes is handled by the user in their code, based on what they want to be extracted.<\/li>\n<li>Passing these nodes to the <strong>ExtractContent<\/strong> method provided below. You must also pass a boolean parameter which states whether these nodes, acting as markers, should be included in the extraction or not.<\/li>\n<li>Retrieving a list of cloned content (copied nodes) specified to be extracted. You can use this list of nodes in any applicable way, for example, creating a new document containing only the selected content.<\/li>\n<\/ol>\n<h2 id=\"how-to-extract-content\">How to Extract Content<\/h2>\n<p>We will work with the document below in this article. As you can see it contains a variety of content. Also note, the document contains a second section beginning in the middle of the first page. A bookmark and comment are also present in the document but are not visible in the screenshot below.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-1.png\" alt=\"extract-content-aspose-words-java\"><\/p>\n<p>To extract the content from your document you need to call the <code>ExtractContent<\/code> method below and pass the appropriate parameters.<\/p>\n<p>The underlying basis of this method involves finding block-level nodes (paragraphs and tables) and cloning them to create identical copies. If the marker nodes passed are block-level then the method is able to simply copy the content on that level and add it to the array.<\/p>\n<p>However, if the marker nodes are inline (a child of a paragraph) then the situation becomes more complex, as it is necessary to split the paragraph at the inline node, be it a run, bookmark fields etc. Content in the cloned parent nodes not present between the markers is removed. This process is used to ensure that the inline nodes will still retain the formatting of the parent paragraph.<\/p>\n<p>The method will also run checks on the nodes passed as parameters and throws an exception if either node is invalid. The parameters to be passed to this method are:<\/p>\n<ol>\n<li>\n<p><strong>StartNode<\/strong> and <strong>EndNode<\/strong>. The first two parameters are the nodes which define where the extraction of the content is to begin and to end at respectively. These nodes can be both block level (<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraph\/\">Paragraph<\/a> , <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/table\/\">Table<\/a> ) or inline level (e.g <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/run\/\">Run<\/a> , <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/fieldstart\/\">FieldStart<\/a> , <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/bookmarkstart\/\">BookmarkStart<\/a> etc.):<\/p>\n<ol>\n<li>To pass a field you should pass the corresponding <strong>FieldStart<\/strong> object.<\/li>\n<li>To pass bookmarks, the <strong>BookmarkStart<\/strong> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/bookmarkend\/\">BookmarkEnd<\/a> nodes should be passed.<\/li>\n<li>To pass comments, the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/commentrangestart\/\">CommentRangeStart<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/commentrangeend\/\">CommentRangeEnd<\/a> nodes should be used.<\/li>\n<\/ol>\n<\/li>\n<li>\n<p><strong>IsInclusive<\/strong>. Defines if the markers are included in the extraction or not. If this option is set to false and the same node or consecutive nodes are passed, then an empty list will be returned:<\/p>\n<ol>\n<li>If a <strong>FieldStart<\/strong> node is passed then this option defines if the whole field is to be included or excluded.<\/li>\n<li>If a <strong>BookmarkStart<\/strong> or <strong>BookmarkEnd<\/strong> node is passed, this option defines if the bookmark is included or just the content between the bookmark range.<\/li>\n<li>If a <strong>CommentRangeStart<\/strong> or <strong>CommentRangeEnd<\/strong> node is passed, this option defines if the comment itself is to be included or just the content in the comment range.<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>The implementation of the <strong>ExtractContent<\/strong> method you can find <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/DocsExamples\/Java\/src\/main\/java\/DocsExamples\/Programming_with_documents\/Contents_management\/ExtractContentHelper.java\">here<\/a>. This method will be referred to in the scenarios in this article.<\/p>\n<p>We will also define a custom method to easily generate a document from extracted nodes. This method is used in many of the scenarios below and simply creates a new document and imports the extracted content into it.<\/p>\n<p>The following code example shows how to take a list of nodes and inserts them into a new document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=generate-document.java\"><\/script>\n\n<h2 id=\"extract-content-between-paragraphs\">Extract Content Between Paragraphs<\/h2>\n<p>This demonstrates how to use the method above to extract content between specific paragraphs. In this case, we want to extract the body of the letter found in the first half of the document.\u00a0We can tell that this is between the 7th and 11th paragraphs.<\/p>\n<p>The code below accomplishes this task. The appropriate paragraphs are extracted using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/#getChild-int-int-boolean\">getChild<\/a> method on the document and passing the specified indices. We then pass these nodes to the <strong>ExtractContent<\/strong> method and state that these are to be included in the extraction. This method will return the copied content between these nodes which are then inserted into a new document.<\/p>\n<p>The following code example shows how to extract the content between specific paragraphs using the <code>ExtractContent<\/code> method above:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-between-paragraphs.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Extract%20content.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>The output document contains the two paragraphs that were extracted.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-2.png\" alt=\"extract-content-result-aspose-words-java\"><\/p>\n<h2 id=\"extract-content-between-different-types-of-nodes\">Extract Content Between Different Types of Nodes<\/h2>\n<p>We can extract content between any combinations of block-level or inline nodes. In this scenario below we will extract the content between the first paragraph and the table in the second section inclusively. We get the markers nodes by calling <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/body\/#getFirstParagraph\">getFirstParagraph<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/compositenode\/#getChild-int-int-boolean\">getChild<\/a> method on the second section of the document to retrieve the appropriate <strong>Paragraph<\/strong> and <strong>Table<\/strong> nodes.\u00a0For a slight variation let\u2019s instead duplicate the content and insert it below the original.<\/p>\n<p>The following code example shows how to extract the content between a paragraph and table using the <strong>ExtractContent<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-between-block-level-nodes.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Extract%20content.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>The content between the paragraph and table has been duplicated below is the result.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-3.png\" alt=\"extract-content-between-paragraphs-aspose-words-java\"><\/p>\n<h2 id=\"extract-content-between-paragraphs-based-on-style\">Extract Content Between Paragraphs Based on Style<\/h2>\n<p>You may need to extract the content between paragraphs of the same or different style, such as between paragraphs marked with heading styles.<\/p>\n<p>The code below shows how to achieve this. It is a simple example which will extract the content between the first instance of the \u201cHeading 1\u201d and \u201cHeader 3\u201d styles without extracting the headings as well. To do this we set the last parameter to false, which specifies that the marker nodes should not be included.<\/p>\n<p>In a proper implementation, this should be run in a loop to extract content between all paragraphs of these styles from the document. The extracted content is copied into a new document.<\/p>\n<p>The following code example shows how to extract content between paragraphs with specific styles using the <strong>ExtractContent<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-between-paragraph-styles.java\"><\/script>\n\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=paragraphs-by-style-name.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Extract%20content.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>Below is the result of the previous operation.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-4.png\" alt=\"extract-content-between-paragraph-style-aspose-words-java\"><\/p>\n<h2 id=\"extract-content-between-specific-runs\">Extract Content Between Specific Runs<\/h2>\n<p>You can extract content between inline nodes such as a <strong>Run<\/strong> as well. <strong>Runs<\/strong> from different paragraphs can be passed as markers.\u00a0The code below shows how to extract specific text in-between the same <strong>Paragraph<\/strong> node.<\/p>\n<p>The following code example shows how to extract content between specific runs of the same paragraph using the <strong>ExtractContent<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-between-runs.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Extract%20content.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>The extracted text is displayed on the console.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-5.png\" alt=\"extract-content-between-runs-aspose-words-java\"><\/p>\n<h2 id=\"extract-content-using-a-field\">Extract Content using a Field<\/h2>\n<p>To use a field as a marker, the <code>FieldStart<\/code> node should be passed. The last parameter to the <code>ExtractContent<\/code> method will define if the entire field is to be included or not.\u00a0Let\u2019s extract the content between the \u201cFullName\u201d merge field and a paragraph in the document. We use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#moveToMergeField(java.lang.String)\">moveToMergeField<\/a> method of <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> class. This will return the <strong>FieldStart<\/strong> node from the name of the merge field passed to it.<\/p>\n<p>In our case let\u2019s set the last parameter passed to the <strong>ExtractContent<\/strong> method to false to exclude the field from the extraction. We will render the extracted content to PDF.<\/p>\n<p>The following code example shows how to extract content between a specific field and paragraph in the document using the <strong>ExtractContent<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-using-field.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Extract%20content.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>The extracted content between the field and paragraph, without the field and paragraph marker nodes rendered to PDF.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-6.png\" alt=\"extract-content-using-field-aspose-words-java\"><\/p>\n<h2 id=\"extract-content-from-a-bookmark\">Extract Content from a Bookmark<\/h2>\n<p>In a document, the content that is defined within a bookmark is encapsulated by the <code>BookmarkStart<\/code> and BookmarkEnd nodes. The content found between these two nodes make up the bookmark. You can pass either of these nodes as any marker, even ones from different bookmarks, as long as the starting marker appears before the ending marker in the document.<\/p>\n<p>In our sample document, we have one bookmark, named \u201cBookmark1\u201d. The content of this bookmark is highlighted content in our document:<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-7.png\" alt=\"extract-content-from-bookmark-aspose-words-java-1\"><\/p>\n<p>We will extract this content into a new document using the code below. The <strong>IsInclusive<\/strong> parameter option shows how to retain or discard the bookmark.<\/p>\n<p>The following code example shows how to extract the content referenced a bookmark using the <strong>ExtractContent<\/strong> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-between-bookmark.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Extract%20content.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>The extracted output with the <code>IsInclusive<\/code> parameter set to true. The copy will retain the bookmark as well.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-8.png\" alt=\"extract-content-from-bookmark-aspose-words-java-2\"><\/p>\n<p>The extracted output with the <strong>IsInclusive<\/strong> parameter set to false. The copy contains the content but without the bookmark.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-9.png\" alt=\"extract-content-from-bookmark-aspose-words-java-3\"><\/p>\n<h2 id=\"extract-content-from-a-comment\">Extract Content from a Comment<\/h2>\n<p>A comment is made up of the CommentRangeStart, CommentRangeEnd and Comment nodes. All of these nodes are inline. The first two nodes encapsulate the content in the document which is referenced by the comment, as seen in the screenshot below.<\/p>\n<p>The <strong>Comment<\/strong> node itself is an <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/inlinestory\/\">InlineStory<\/a> that can contain paragraphs and runs. It represents the message of the comment as seen as a comment bubble in the review pane. As this node is inline and a descendant of a body you can also extract the content from inside this message as well.<\/p>\n<p>In our document we have one comment. Let\u2019s display it by showing markup in the Review tab:<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-10.png\" alt=\"extract-content-from-comment-aspose-words-java-1\"><\/p>\n<p>The comment encapsulates the heading, first paragraph and the table in the second section.\u00a0Let\u2019s extract this comment into a new document. The <strong>IsInclusive<\/strong> option dictates if the comment itself is kept or discarded.<\/p>\n<p>The following code example shows how to do this is below:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-between-comment-range.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Extract%20content.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>Firstly the extracted output with the <code>IsInclusive<\/code> parameter set to true. The copy will contain the comment as well.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-11.png\" alt=\"extract-content-from-comment-aspose-words-java-2\"><\/p>\n<p>Secondly the extracted output with <strong>isInclusive<\/strong> set to false. The copy contains the content but without the comment.<\/p>\n<p><img src=\"extract-content-from-comment-aspose-words-java-12.png\" alt=\"extract-content-from-comment-aspose-words-java-12\"><\/p>\n<h2 id=\"extract-content-using-documentvisitor\">Extract Content using DocumentVisitor<\/h2>\n<p>Aspose.Words can be used not only for creating Microsoft Word documents by building them dynamically or merging templates with data, but also for parsing documents in order to extract separate document elements such as headers, footers, paragraphs, tables, images, and others. Another possible task is to find all text of specific formatting or style.<\/p>\n<p>Use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/\">DocumentVisitor<\/a> class to implement this usage scenario. This class corresponds to the well-known Visitor design pattern. With <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/\">DocumentVisitor<\/a>, you can define and execute custom operations that require enumeration over the document tree.<\/p>\n<p><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/\">DocumentVisitor<\/a> provides a set of <strong>VisitXXX<\/strong> methods that are invoked when a particular document element (node) is encountered. For example, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/#visitParagraphStart-com.aspose.words.Paragraph\">VisitParagraphStart<\/a> is called when the beginning of a text paragraph is found and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/#visitParagraphEnd-com.aspose.words.Paragraph\">VisitParagraphEnd<\/a> is called when the end of a text paragraph is found. Each <strong>DocumentVisitor.VisitXXX<\/strong> method accepts the corresponding object that it encounters so you can use it as needed (say retrieve the formatting), e.g. both <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/#visitParagraphStart-com.aspose.words.Paragraph\">VisitParagraphStart<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/#visitParagraphEnd-com.aspose.words.Paragraph\">VisitParagraphEnd<\/a> accept a <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraph\/\">Paragraph<\/a> object.<\/p>\n<p>Each <strong>DocumentVisitor.VisitXXX<\/strong> method returns a <strong>VisitorAction<\/strong> value that controls the enumeration of nodes. You can request either to continue the enumeration, skip the current node (but continue the enumeration), or stop the enumeration of nodes.<\/p>\n<p>These are the steps you should follow to programmatically determine and extract various parts of a document:<\/p>\n<ul>\n<li>Create a class derived from <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/\">DocumentVisitor<\/a>.<\/li>\n<li>Override and provide implementations for some or all of the <strong>DocumentVisitor.VisitXXX<\/strong> methods to perform some custom operations.<\/li>\n<li>Call <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#accept-com.aspose.words.DocumentVisitor\">Node.accept<\/a> on the node from where you want to start the enumeration. For example, if you want to enumerate the whole document, use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#accept-com.aspose.words.DocumentVisitor\">accept(DocumentVisitor)<\/a>.<\/li>\n<\/ul>\n<p><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/\">DocumentVisitor<\/a> provides default implementations for all of the <strong>DocumentVisitor.VisitXXX<\/strong> methods. This makes it easier to create new document visitors as only the methods required for the particular visitor need to be overridden. It is not necessary to override all of the visitor methods.<\/p>\n<p>The following example shows how to use the Visitor pattern to add new operations to the Aspose.Words object model. In this case, we create a simple document converter into a text format:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-content-using-document-visitor.java\"><\/script>\n\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=convert-doc-to-txt.java\"><\/script>\n\n<h2 id=\"extract-text-only\">Extract Text Only<\/h2>\n<p>The ways to retrieve text from the document are:<\/p>\n<ul>\n<li>Use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#save-java.io.OutputStream-com.aspose.words.SaveOptions\">Document.save<\/a> with <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/saveformat\/\">SaveFormat<\/a> to save as plain text into a file or stream<\/li>\n<li>Use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#toString-com.aspose.words.SaveOptions\">Node.toString<\/a> and pass the <code>SaveFormat.Text<\/code> parameter. Internally, this invokes save as text into a memory stream and returns the resulting string<\/li>\n<li>Use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getText\">Node.getText<\/a> to retrieve text with all Microsoft Word control characters including field codes<\/li>\n<li>Implement a custom <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentvisitor\/\">DocumentVisitor<\/a> to perform customized extraction<\/li>\n<\/ul>\n<h3 id=\"using-nodegettext-and-nodetostring\">Using <code>Node.GetText<\/code> and <code>Node.ToString<\/code><\/h3>\n<p>A Word document can contains control characters that designate special elements such as field, end of the cell, end of section etc. The full list of possible Word control characters is defined in the <strong>ControlChar<\/strong> class. The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#getText\">GetText<\/a> method returns text with all of the control character characters present in the node.<\/p>\n<p>Calling ToString returns the plain text representation of the document only without control characters. For further information on exporting as plain text see <strong>Using SaveFormat.Text<\/strong>.<\/p>\n<p>The following code example shows the difference between calling the <strong>GetText<\/strong> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/node\/#toString\">ToString<\/a> methods on a node:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=simple-extract-text.java\"><\/script>\n\n<h3 id=\"using-saveformattext\">Using <code>SaveFormat.Text<\/code><\/h3>\n<p>This example saves the document as follows:<\/p>\n<ul>\n<li>Filters out field characters and field codes, shape, footnote, endnote and comment references<\/li>\n<li>Replaces end of paragraph <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/controlchar\/\">ControlChar.Cr<\/a> characters with <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/controlchar\/\">ControlChar.CrLf<\/a> combinations<\/li>\n<li>Uses UTF8 encoding<\/li>\n<\/ul>\n<p>The following code example shows how to save a document in TXT format:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=docx-to-txt.java\"><\/script>\n\n<h2 id=\"extract-images-from-shapes\">Extract Images from Shapes<\/h2>\n<p>You may need to extract document images to perform some tasks. Aspose.Words allows you to do this as well.<\/p>\n<p>The following code example shows how to extract images from a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/1975a35426bcd195a2e7c61d20a1580c.js?file=extract-images.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I extract content between two specific nodes in a Word document using Aspose.Words for Java?<br>\n<strong>A:<\/strong> Locate the start and end nodes (e.g., Paragraph, Run, FieldStart, BookmarkStart) using the document object model, then call the provided <code>ExtractContent(Node startNode, Node endNode, boolean isInclusive)<\/code> helper. The method returns a list of cloned nodes that you can insert into a new <code>Document<\/code> with <code>Document.appendDocument<\/code> or by importing each node individually.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What does the <strong>IsInclusive<\/strong> parameter control in the <code>ExtractContent<\/code> method?<br>\n<strong>A:<\/strong> When <strong>IsInclusive<\/strong> is <code>true<\/code>, the start and end marker nodes themselves are included in the extracted range. When <code>false<\/code>, only the content <em>between<\/em> the markers is returned. This is useful for excluding merge fields, bookmarks, or comment markers from the result.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I use a bookmark or a comment as markers for extraction?<br>\n<strong>A:<\/strong> Yes. Pass the <code>BookmarkStart<\/code>\/<code>BookmarkEnd<\/code> nodes or the <code>CommentRangeStart<\/code>\/<code>CommentRangeEnd<\/code> nodes as the start and end parameters. The helper will correctly handle inline markers and will retain or discard the bookmark\/comment based on the <strong>IsInclusive<\/strong> flag.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I extract only the plain text of a document without formatting or control characters?<br>\n<strong>A:<\/strong> Use <code>Node.getText()<\/code> for raw text with control characters, or <code>Node.toString(new SaveOptions(SaveFormat.Text))<\/code> to obtain clean plain text. Alternatively, save the whole document with <code>Document.save(outputStream, SaveFormat.Text)<\/code> for a UTF\u20118 encoded text file.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to extract images from a document while extracting other content?<br>\n<strong>A:<\/strong> Yes. Iterate through the document\u2019s <code>NodeType.SHAPE<\/code> nodes, check <code>Shape.getShapeType() == ShapeType.IMAGE<\/code>, and call <code>Shape.getImageData().toByteArray()<\/code> to obtain the image bytes. You can store the images separately and still use the <code>ExtractContent<\/code> method for the surrounding text, tables, or paragraphs.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Headers and Footers in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-headers-and-footers\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-headers-and-footers\/","description":"\n        \n        \n        <p>Aspose.Words allows users to work with headers and footers in a document. A header is text that is placed at the top of a page, and a footer is text at the bottom of a page. Typically, these areas are used to insert information that should be repeated on all or some pages of the document, such as page numbers, creation date, company information, and so on.<\/p>\n<h2 id=\"create-headers-or-footers-using-documentbuilder\">Create Headers or Footers using DocumentBuilder<\/h2>\n<p>If you want to add a document header or footer programmatically, the easiest way is to use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> class to do it.<\/p>\n<p>The following code example shows how to add a header and footer for document pages:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=create-header-footer.java\"><\/script>\n\n<h2 id=\"specify-header-or-footer-options\">Specify Header or Footer Options<\/h2>\n<p>When you add a header or footer to a document, you can set some advanced properties. Aspose.Words provides users with the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/headerfooter\/\">HeaderFooter<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/headerfootercollection\/\">HeaderFooterCollection<\/a> classes, as well as <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/headerfootertype\/\">HeaderFooterType<\/a> enumeration that give you more control over the header and footer customization process.<\/p>\n<h3 id=\"specify-header-or-footer-type\">Specify Header or Footer Type<\/h3>\n<p>You can specify three different header types and three different footer types for one document:<\/p>\n<ol>\n<li>Header and\/or footer for the first page<\/li>\n<li>Header and\/or footer for even pages<\/li>\n<li>Header and\/or footer for odd pages<\/li>\n<\/ol>\n<p>The following code example shows how to add a header for odd document pages:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=header-footer-type.java\"><\/script>\n\n<h3 id=\"specify-whether-to-display-different-headers-or-footers-for-the-first-page\">Specify Whether to Display Different Headers or Footers for the First Page<\/h3>\n<p>As said above, you can also set a different header or footer for the first page. To do this, you need to set the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/#getDifferentFirstPageHeaderFooter\">DifferentFirstPageHeaderFooter<\/a> flag to <code>true<\/code> and then specyfy the <strong>HeaderFirst<\/strong> or <strong>FooterFirst<\/strong> value.<\/p>\n<p>The following code example shows how to set the header for the first page only:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=different-first-page.java\"><\/script>\n\n<h3 id=\"specify-whether-to-display-different-headers-or-footers-for-odd-or-even-pages\">Specify Whether to Display Different Headers or Footers for Odd or Even Pages<\/h3>\n<p>Next, you will want to set different headers or footers for odd and even pages in a document. To do this, you need to set the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/pagesetup\/#getOddAndEvenPagesHeaderFooter\">OddAndEvenPagesHeaderFooter<\/a> flag to <code>true<\/code> and then specyfy the values <strong>HeaderPrimary<\/strong> and <strong>HeaderEven<\/strong>, or <strong>FooterPrimary<\/strong> and <strong>FooterEven<\/strong>.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=odd-even-pages.java\"><\/script>\n\n<h3 id=\"insert-an-absolutely-positioned-image-into-the-header\">Insert an Absolutely Positioned Image into the Header<\/h3>\n<p>To place an image in a header or footer, use the <strong>HeaderPrimary<\/strong> header type or the <strong>FooterPrimary<\/strong> footer type and the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertImage-byte\">InsertImage<\/a> method.<\/p>\n<p>The following code example shows how to add an image to a header:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=insert-image.java\"><\/script>\n\n<h3 id=\"set-font-and-paragraph-properties-for-header-or-footer-text\">Set Font and Paragraph Properties for Header or Footer Text<\/h3>\n<p>With Aspose.Words you can set the font and paragraph properties, use the <strong>HeaderPrimary<\/strong> header type or the <strong>FooterPrimary<\/strong> footer type, as well as methods and properties for working with the fonts and paragraphs you use for the document body.<\/p>\n<p>The following code example shows how to set the text in the header to Arial, bold, size 14, and center alignment:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=font-props.java\"><\/script>\n\n<h3 id=\"insert-page-numbers-into-the-header-or-footer\">Insert Page Numbers into the Header or Footer<\/h3>\n<p>If necessary, you can add page numbers to the header or footer. To do this, use the <strong>HeaderPrimary<\/strong> header type or the <strong>FooterPrimary<\/strong> footer type and the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertField-int-boolean\">InsertField<\/a> method to add the required field.<\/p>\n<p>The following code example shows how to add page numbers to the footer on the right:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=page-numbers.java\"><\/script>\n\n<h3 id=\"use-headers-or-footers-defined-in-the-previous-section\">Use Headers or Footers Defined in the Previous Section<\/h3>\n<p>If you need to copy the header or footer from the previous section, you can do that too.<\/p>\n<p>The following code example shows how to copy the header or footer from the previous section:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=copy-headers-footers-from-previous-section.java\"><\/script>\n\n<h3 id=\"ensure-header-or-footer-appearance-when-using-different-page-orientations-and-page-size\">Ensure Header or Footer appearance when Using Different Page Orientations and Page Size<\/h3>\n<p>Aspose.Words allows you to provide the appearance of a header or footer when using different orientations and page sizes.<\/p>\n<p>The following example shows how to do this:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=link-to-previous-header-footer.java\"><\/script>\n\n<h2 id=\"how-to-remove-only-headers-or-only-footers\">How to Remove Only Headers or Only Footers<\/h2>\n<p>Each section in a document can have up to three headers and up to three footers (for first, even, and odd pages). If you want to remove all headers or all footers in a document, you need to loop through all the sections and remove each corresponding header node or footer node.<\/p>\n<p>The following code example shows how to remove all footers from all sections but leave headers intact. You can remove only headers in a similar way:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/58431f54e34e5597f8cbaf97481d5321.js?file=remove-footers.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Footer.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I set a different header or footer only for the first page of a document?<br>\n<strong>A:<\/strong> Set <code>PageSetup.setDifferentFirstPageHeaderFooter(true)<\/code> on the section. Then use <code>HeaderFooterType.HEADER_FIRST<\/code> or <code>FooterFirst<\/code> to access and edit the first\u2011page header\/footer.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What steps are required to have separate headers\/footers for odd and even pages?<br>\n<strong>A:<\/strong> Enable <code>PageSetup.setOddAndEvenPagesHeaderFooter(true)<\/code>. After that, create or modify <code>HeaderPrimary<\/code>\/<code>FooterPrimary<\/code> for odd pages and <code>HeaderEven<\/code>\/<code>FooterEven<\/code> for even pages.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I copy the header\/footer from the previous section without recreating it manually?<br>\n<strong>A:<\/strong> Set <code>section.getHeadersFooters().linkToPrevious(true)<\/code>. The section will automatically use the header\/footer objects from the preceding section.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I use <code>DocumentBuilder<\/code> to move directly to a header or footer of a specific section?<br>\n<strong>A:<\/strong> Yes. Call <code>builder.moveToHeaderFooter(section.getHeadersFooters().getByHeaderFooterType(HeaderFooterType.HEADER_PRIMARY))<\/code>. After moving, you can insert text, images, or fields.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I remove only the footers (or only the headers) from every section in a document?<br>\n<strong>A:<\/strong> Iterate through <code>document.getSections()<\/code>, then for each section call <code>section.getHeadersFooters().removeAll(HeaderFooterType.FOOTER_PRIMARY)<\/code>, <code>FOOTER_FIRST<\/code>, and <code>FOOTER_EVEN<\/code> (or the corresponding header types) to delete only the unwanted parts.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Footnote and Endnote in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-footnote-and-endnote\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-footnote-and-endnote\/","description":"\n        \n        \n        <p>Aspose.Words also provides some classes, methods and properties for working with footnotes and endnotes.<\/p>\n<h2 id=\"insert-endnote-and-set-numbering-options\">Insert Endnote and Set Numbering Options<\/h2>\n<p>If you want to insert a footnote or an endnote in a Word document, please use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertFootnote-int-java.lang.String\">InsertFootnote<\/a> method. This method inserts a footnote or endnote into the document.<\/p>\n<p><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/endnoteoptions\/\">EndnoteOptions<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/footnoteoptions\/\">FootnoteOptions<\/a> classes represent numbering options for footnote and endnote.<\/p>\n<p>The following code example shows how to insert endnote into the document and set its numbering options:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithFootnote-SetEndnoteOptions.java\"><\/script>\n\n<h2 id=\"set-number-of-footnote-layout-columns\">Set Number of Footnote Layout Columns<\/h2>\n<p>You can set the number of footnote layout columns using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/footnoteoptions\/#getColumns\">Columns<\/a> property. If this property has the value of 0, the footnotes area is formatted with a number of columns based on the number of columns on the displayed page.<\/p>\n<p>The following code example shows how to set the number of columns for footnote layout:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithFootnote-SetFootNoteColumns.java\"><\/script>\n\n<h2 id=\"set-the-position-of-footnote-and-endnote\">Set the Position of Footnote and EndNote<\/h2>\n<p>The footnote position can be at the bottom of each page or beneath the text on each page. The endnote position can be at the end of the section or at the end of the document.<\/p>\n<p>The following code example shows how to set the position of footnote and endnote:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithFootnote-SetFootnoteAndEndNotePosition.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I insert a footnote or an endnote with DocumentBuilder?<br>\n<strong>A:<\/strong> Use <code>DocumentBuilder.insertFootnote(FootnoteType type, String text)<\/code>. Pass <code>FootnoteType.FOOTNOTE<\/code> for a footnote or <code>FootnoteType.ENDNOTE<\/code> for an endnote, and provide the content string.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I change the numbering style (e.g., Roman, Arabic) of footnotes or endnotes?<br>\n<strong>A:<\/strong> Yes. Access the options via <code>Document.getFootnoteOptions()<\/code> or <code>Document.getEndnoteOptions()<\/code> and call <code>setNumberStyle(FootnoteNumberStyle style)<\/code> \/ <code>setNumberStyle(EndnoteNumberStyle style)<\/code> to set the desired numbering format.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I control how many columns footnotes are displayed in?<br>\n<strong>A:<\/strong> Set the <code>Columns<\/code> property on the document\u2019s <code>FootnoteOptions<\/code>: <code>document.getFootnoteOptions().setColumns(int columns)<\/code>. A value of <code>0<\/code> lets Word decide based on page layout.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What properties determine where footnotes and endnotes appear in the document?<br>\n<strong>A:<\/strong> Use <code>FootnoteOptions.setPosition(FootnotePosition position)<\/code> to choose between <code>BOTTOM_OF_PAGE<\/code> or <code>BENEATH_TEXT<\/code>. For endnotes, use <code>EndnoteOptions.setPosition(EndnotePosition position)<\/code> with values <code>END_OF_SECTION<\/code> or <code>END_OF_DOCUMENT<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I retrieve existing footnotes or endnotes from a loaded document?<br>\n<strong>A:<\/strong> The <code>Document<\/code> class provides <code>getFootnotes()<\/code> and <code>getEndnotes()<\/code> collections. Iterate over them, e.g., <code>for (Footnote footnote : document.getFootnotes()) { \/* process *\/ }<\/code>. This lets you read, modify, or remove individual notes.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Table of Contents in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-table-of-contents\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-table-of-contents\/","description":"\n        \n        \n        <p>Often you will work with documents containing a table of contents (TOC). Using Aspose.Words you can insert your own table of contents or completely rebuild the existing table of contents in the document using just a few lines of code.<\/p>\n<p>This article outlines how to work with the table of contents field and demonstrates:<\/p>\n<ul>\n<li>How to insert a brand new TOC.<\/li>\n<li>Update new or existing TOCs in the document.<\/li>\n<li>Specify switches to control the formatting and overall structure of the TOC.<\/li>\n<li>How to modify the styles and appearance of the table of contents.<\/li>\n<li>How to remove an entire <code>TOC<\/code> field along with all entries from the document.<\/li>\n<\/ul>\n<h2 id=\"insert-table-of-contents-programmatically\">Insert Table of Contents Programmatically<\/h2>\n<p>You can insert a <code>TOC<\/code> (table of contents) field into the document at the current position by calling the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertTableOfContents-java.lang.String\">InsertTableOfContents<\/a> method.<\/p>\n<p>A table of contents in a Word document can be built in several ways and formatted using a variety of options. The field switches that you pass to the method control the way the table is built and displayed in your document.<\/p>\n<p>The default switches that are used in a <code>TOC<\/code> inserted in Microsoft Word are <strong>\u201c\\o \u201c1-3 \\h \\z \\u\u201d<\/strong>. Descriptions of these switches as well as a list of supported switches can be found later in the article. You can either use that guide to obtain the correct switches or if you already have a document containing the similar <code>TOC<\/code> that you want you can show field codes (<em>ALT+F9<\/em>) and copy the switches directly from the field.<\/p>\n<p>The following code example shows how to insert a Table of Contents field into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-InsertATableOfContentsField-InsertATableOfContentsField.java\"><\/script>\n\n<p>The following code\u00a0example demonstrates how to insert a Table of contents (TOC) into a document using heading styles as entries:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-InsertATableOfContentsUsingHeadingStyles-InsertATableOfContentsUsingHeadingStyles.java\"><\/script>\n\n<p>The code demonstrates the new table of contents is inserted into a blank document. The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> class is then used to insert some sample content formatting with the appropriate heading styles which are used to mark the content to be included in the TOC. The next lines then populate the <code>TOC<\/code> by updating the fields and the page layout of the document.<\/p>\n<p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-1.png\" alt=\"insert-table-of-contents-field-aspose-words-java\"><\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nWithout the methods used in the example, when you open the output document, you would find the <code>TOC<\/code> field, but with no visible content. This is because the <code>TOC<\/code> field has been inserted but is not yet populated until it\u2019s updated in the document. Further information about this is discussed in the next section.\n<\/div>\n\n<h2 id=\"update-table-of-contents\">Update Table of Contents<\/h2>\n<p>Aspose.Words allows you to completely update a <code>TOC<\/code> with only a few lines of code. This can be done to populate a newly inserted <code>TOC<\/code> or to update an existing <code>TOC<\/code> after changes to the document have been made.<\/p>\n<p>The following two methods must be used to update the <code>TOC<\/code> fields in the document:<\/p>\n<ol>\n<li><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/Document#updateFields()\">Document.updateFields()<\/a><\/li>\n<li><a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/Document#updatePageLayout()\">Document.updatePageLayout()<\/a><\/li>\n<\/ol>\n<p>Please note that these two update methods are required to be called in that order. If reversed the table of contents will be populated but no page numbers will be displayed. Any number of different TOCs can be updated. These methods will automatically update all TOCs found in the document.<\/p>\n<p>The following code\u00a0example shows how to completely rebuild <code>TOC<\/code> fields in the document by invoking field updates:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-InsertATableOfContentsField-UpdateTableOfContents.java\"><\/script>\n\n<p>The first call to <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#updateFields\">Document.updateFields()<\/a> will build the <code>TOC<\/code>, all text entries are populated and the <code>TOC<\/code> appears almost complete. The only thing missing is the page numbers which for now are displayed with \u201c?\u201d.<\/p>\n<p>The second call to <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#updatePageLayout\">Document.updatePageLayout()<\/a> will build the layout of the document in memory. This needs to be done to gather the page numbers of the entries. The correct page numbers calculated from this call are then inserted into the TOC.<\/p>\n<h2 id=\"use-switches-to-control-table-of-contents-behavior\">Use Switches to Control Table of Contents Behavior<\/h2>\n<p>As with any other field, the <code>TOC<\/code> field can accept switches defined within the field code that controls how the table of contents is built. Certain switches are used to control which entries are included and at what level while others are used to control the appearance of the TOC. Switches can be combined together to allow a complex table of contents to be produced.<\/p>\n<p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-2.png\" alt=\"ccontrol-table-of-contents-field-aspose-words-java\"><\/p>\n<p>By default, these switches above are included when inserting a default <code>TOC<\/code> in the document. A <code>TOC<\/code> with no switches will include content from the built-in heading styles (as if the \\O switch is set).<\/p>\n<p>The available <code>TOC<\/code> switches that are supported by Aspose.Words are listed below and their uses are described in detail. They can be divided into separate sections based on their type. The switches in the first section define what content to include in the <code>TOC<\/code> and the switches in the second section control the appearance of the TOC.<\/p>\n<p>If a switch is not listed here then it is currently unsupported.\u00a0 All switches will be supported in future versions. We are adding further support to every release.<\/p>\n<h3 id=\"entry-marking-switches\">Entry Marking Switches<\/h3>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">Switch<\/th>\n<th style=\"text-align:left\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\"><strong>Heading Styles<\/strong> <br> <em>(\\O Switch)<\/em>\u00a0<br>\u00a0<\/td>\n<td style=\"text-align:left\"><p>This switch defines that the <code>TOC<\/code> should be built off the built-in heading styles. In Microsoft Word, these are defined by Heading 1 \u2013 Heading 9. In Aspose.Words these styles are represented by the corresponding StyleIdentifier enumeration. This enumeration represents a locale-independent identifier of a style, for example, <code>StyleIdentifier.Heading1<\/code> represents the Heading 1 style. Using this, the formatting and properties of the style can be retrieved from the Style collection of the document. The corresponding Style class can be retrieved from the <code>Document.Styles<\/code> collection by using the indexed property of type StyleIdentifier. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-3.png\" alt=\"style-table-of-contents-field-aspose-words-java\"><\/p><p><br><br>Any content formatted with these styles is included in the table of contents. The level of the heading will define the corresponding hierarchical level of the entry in the TOC. For instance, a paragraph with Heading 1 style will be treated as the first level in the <code>TOC<\/code> whereas a paragraph with Heading 2 will be treated as the next level in the hierarchy and so forth.<\/p><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Outline Levels<\/strong> <br> <em>(\\U switch)<\/em> <br>\u00a0<\/td>\n<td style=\"text-align:left\"><p>Each paragraph can define an outline level under Paragraph options. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-4.png\" alt=\"modify-table-of-contents-field-aspose-words-java\"><\/p><p><br><br>This setting dictates which level this paragraph should be treated in the document hierarchy. This is a commonly used practice used to easily structure the layout of a document. This hierarchy can be viewed by changing to Outline View in Microsoft Word. Similar to heading styles, there can be 1 \u2013 9 outline levels in addition to the \u201cBody Text\u201d level. Outline levels 1 \u2013 9 will appear in the <code>TOC<\/code> in the corresponding level of the hierarchy <br>Any content with an outline level either set in the paragraph style or directly on the paragraph itself is included in the TOC. In Aspose.Words the outline level is represented by the <code>ParagraphFormat.OutlineLevel<\/code> property of the Paragraph node. The outline level of a paragraph style is represented in the same way by the <code>Style.ParagraphFormat<\/code> property.<\/p>\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\n <\/p><p>Note that built-in heading styles such as Heading 1 have an outline level compulsory set in style settings.<\/p><p>\n<\/div>\n<\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Custom Styles<\/strong> <br> <em>(\\T switch)<\/em> <br>\u00a0<\/td>\n<td style=\"text-align:left\"><p>This switch will allow custom styles to be used when collecting entries to be used in the TOC. This is often used in conjunction with the \\O switch to include custom styles along with built-in heading styles in the TOC. <br>The parameters of the switch should be enclosed within speech marks. Many custom styles can be included, for each style, the name should be specified followed by a comma followed by the level that the style should appear in the <code>TOC<\/code> as. Further styles are also separated by a comma as well. <br>For instance\u00a0<\/p><div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">{<\/span> <span class=\"n\">TOC<\/span> <span class=\"err\">\\<\/span><span class=\"n\">o<\/span> <span class=\"s\">&#34;1-3&#34;<\/span> <span class=\"err\">\\<\/span><span class=\"n\">t<\/span> <span class=\"s\">&#34;CustomHeading1, 1,   CustomHeading2, 2&#34;<\/span><span class=\"p\">}<\/span>\n<\/code><\/pre><\/div><p>will use content styled with CustomHeading1 as level 1 content in the <code>TOC<\/code> and CustomHeading2 as level 2.<\/p><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">Use TC Fields <br> <em>(\\F and \\L Switches)<\/em> <br>\u00a0<\/td>\n<td style=\"text-align:left\"><p>In older versions of Microsoft Word, the only way to build a <code>TOC<\/code> was the use of TC fields. These fields are inserted hidden into the document even when field codes are shown. They include the text that should be displayed in the entry and the <code>TOC<\/code> is built from them. This functionality is now not used very often but may still be useful in some occasions to include entries in the <code>TOC<\/code> which are not indented to be visible in the document. <br>When inserted these fields appear hidden even when field codes are displayed. They cannot be seen without showing hidden content. To see these fields Show paragraph formatting must be selected. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-5.png\" alt=\"setup-table-of-contents-field-aspose-words-java\"><\/p><p>These fields can be inserted into a document at any position like any other field and are represented by the <code>FieldType.FieldTOCEntry<\/code> enumeration.<br>The \\F switch in a <code>TOC<\/code> is used to specify that TC fields should be used as entries. The switch on its own without any extra identifier means that any TC field in the document will be included. Any extra parameter, often a single letter, will designate that only TC fields that have a matching \\f switch will be included in the TOC. For instance *<\/p><div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">{<\/span> <span class=\"n\">TOC<\/span> <span class=\"err\">\\<\/span><span class=\"n\">f<\/span> <span class=\"n\">t<\/span> <span class=\"p\">}<\/span>\n<\/code><\/pre><\/div><p>will only include TC fields such as\u00a0<\/p><div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">{<\/span> <span class=\"n\">TC<\/span> <span class=\"err\">\\<\/span><span class=\"n\">f<\/span> <span class=\"n\">t<\/span> <span class=\"p\">}<\/span>\n<\/code><\/pre><\/div><p>The <code>TOC<\/code> field also has a related switch, the \\L switch specifies that only TC field with levels within the specified range are included.\u00a0 <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-6.png\" alt=\"table-of-contents-field-aspose-words-java\"><\/p><p><br><br>The <code>TC<\/code> fields themselves also can have <code>{several, multiple, a few, many, numerous}<\/code> switches set. These are:<\/p><p>- \\F \u2013 Explained above.*<\/p><p>- \\L \u2013 Defines which level in the <code>TOC<\/code> this TC field will appear in. A <code>TOC<\/code> which uses this same switch will only include this TC field if it\u2019s within the specified range.<\/p><p>- _\\N \u2013 The page numbering for this <code>TOC<\/code> entry is not displayed. Sample code of how to insert TC fields can be found in the next section.<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3 id=\"appearance-related-switches\">Appearance Related Switches<\/h3>\n<table>\n<thead>\n<tr>\n<th style=\"text-align:left\">Switch<\/th>\n<th style=\"text-align:left\">Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"text-align:left\"><strong>Omit Page Numbers<\/strong> <br> <em>(\\N Switch)<\/em>\u00a0<\/td>\n<td style=\"text-align:left\"><p>This switch is used to hide page numbers for certain levels of the TOC. For example, you can define\u00a0<\/p><div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"p\">{<\/span><span class=\"n\">TOC<\/span> <span class=\"err\">\\<\/span><span class=\"n\">o<\/span> <span class=\"s\">&#34;1-4&#34;<\/span> <span class=\"err\">\\<\/span><span class=\"n\">n<\/span> <span class=\"s\">&#34;3-4&#34;<\/span> <span class=\"p\">}<\/span>\n<\/code><\/pre><\/div><p>and the page numbers on the entries of levels 3 and four will be hidden along with the leader dots (if there are any). To specify only one level a range should still be used, for example, &ldquo;1-1&rdquo; will exclude page numbers only for the first level. <br>Supplying no level range will omit page numbers for all levels in the TOC. This is useful to set when exporting a document to HTML or a similar format. This is because HTML based formats don\u2019t have any page concept and thus don\u2019t need any page numbering. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-7.png\" alt=\"table-of-contents-aspose-words-java\"><\/p><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\">Insert As Hyperlinks <br> <em>(\\H Switch)<\/em>\u00a0<\/td>\n<td style=\"text-align:left\"><p>This switch specifies that <code>TOC<\/code> entries are inserted as hyperlinks. When viewing a document in Microsoft Word these entries will still appear as normal text inside the <code>TOC<\/code> but are hyperlinked and thus can be used to navigate to the position of the original entry in the document by using <em>Ctrl + Left Click<\/em> in Microsoft Word. When this switch is included then these links are also preserved in other formats. For instance, in HTML based formats including EPUB and rendered formats such as PDF and XPS, these will be exported as working links. <br>Without this switch set, the <code>TOC<\/code> in all of these outputs will be exported as plain text and will not demonstrate this behavior.\u00a0 If a document is opened in MS Word the text of the entries will also not be clickable in this way but the page numbers can still be used to navigate to the original entry. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-8.png\" alt=\"tree-table-of-contents-field-aspose-words-java\"><\/p><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Set Separator Character<\/strong> <br> <em>(\\P Switch)<\/em>\u00a0<br>\u00a0<\/td>\n<td style=\"text-align:left\"><p>This switch allows the content separating the title of the entry and page numbering to be easily changed in the TOC. The separator to use should be specified after this switch and enclosed in speech marks. <br>Contrary to what is documented in Office documentation, only one character can be used instead of up to five. This applies to both MS Word and Aspose.Words. <br>Using this switch is not recommended as it does not allow much control over what it used to separate entries and page numbers in the TOC. Instead, it is recommended to edit the appropriate <code>TOC<\/code> style such as <code>StyleIdentifier.TOC1<\/code> and from there edit the leader style with access to specific font members etc. Further details of how to do this can be found later in the article. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-9.png\" alt=\"list-table-of-contents-field-aspose-words-java\"><\/p><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Preserve Tab Entries<\/strong> <br> <em>(\\W Switch)<\/em>\u00a0<\/td>\n<td style=\"text-align:left\"><p>Using this switch will specify that any entries that have a tab character, for instance, a heading that has a tab at the end of the line, will be retained as a proper tab character when populating the TOC. This means the function of the tab character will be present in the <code>TOC<\/code> and can be used to format the entry. For example, certain entries may use tab stops and tab characters to evenly space out the text. As long as the corresponding <code>TOC<\/code> level defines the equivalent tab stops then the generated <code>TOC<\/code> entries will appear with similar spacing. <br><br>In the same situation if this switch was not defined then the tab characters would be converted to white space equivalent as non-functioning tabs. The output would then not appear as expected. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-10.png\" alt=\"tab-table-of-contents-field-aspose-words-java\"><\/p><\/td>\n<\/tr>\n<tr>\n<td style=\"text-align:left\"><strong>Preserve New Line Entries<\/strong> <br> <em>(\\X Switch)<\/em> <br>\u00a0<\/td>\n<td style=\"text-align:left\"><p>Similar to the switch above, this switch specifies that headings spanning over multiple lines (using newline characters, not separate paragraphs) will be preserved as they are in the generated TOC. For example, a heading which is to spread across multiple lines can use the new line character (Ctrl + Enter or <code>ControlChar.LineBreak<\/code>) to separate content across different lines. With this switch specified, the entry in the <code>TOC<\/code> will preserve these new line characters as shown below. <br><br>In this situation, if the switch is not defined then the new line characters are converted to a single white space. <\/p><p><img src=\"how-to-insert-and-work-with-the-table-of-contents-field-11.png\" alt=\"tab-space-table-of-contents-field-aspose-words-java\"><\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"insert-tc-fields\">Insert TC Fields<\/h2>\n<p>You can insert a new TC field at the current position of the <code>DocumentBuilder<\/code> by calling the <code>DocumentBuilder.InsertField<\/code> method and specifying the field name as TC along with any switches that are needed.<\/p>\n<p>The following code\u00a0example shows how to insert a <code>TC<\/code> field into the document using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a>.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-InsertTCField-InsertTCField.java\"><\/script>\n\n<p>Often a specific line of text is designated for the <code>TOC<\/code> and is marked with a <code>TC<\/code> field. \u00a0The easy way to do this in MS Word is to highlight the text and press <em>ALT+SHIFT+O<\/em>. This automatically creates a <code>TC<\/code> field using the selected text. The same technique can be accomplished through code. The code below will find text matching the input and insert a <code>TC<\/code> field in the same position as the text. The code is based on the same technique used in the article.\u00a0The following code\u00a0example shows how to find and insert a <code>TC<\/code> field at the text in a document.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-FindAndInsertATCField-InsertTCFieldHandler.java\"><\/script>\n\n<h2 id=\"modify-a-table-of-contents\">Modify a Table of Contents<\/h2>\n<h3 id=\"change-the-formatting-of-styles\">Change the Formatting of Styles<\/h3>\n<p>The formatting of entries in the <code>TOC<\/code> does not use the original styles of the marked entries, instead, each level is formatted using an equivalent <code>TOC<\/code> style. For example, the first level in the <code>TOC<\/code> is formatted with the <strong>TOC1<\/strong> style, the second level formatted with the <strong>TOC2<\/strong> style and so on. This means that to change the look of the <code>TOC<\/code> these styles must be modified. In Aspose.Words these styles are represented by the locale-independent <code>StyleIdentifier.TOC1<\/code> through to <code>StyleIdentifier.TOC9<\/code> and can be retrieved from the <code>Document.Styles<\/code> collection using these identifiers.<\/p>\n<p>Once the appropriate style of the document has been retrieved the formatting for this style can be modified. Any changes to these styles will be automatically reflected in the TOCs in the document.<\/p>\n<p>The following code\u00a0example changes a formatting property used in the first level <code>TOC<\/code> style.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-ModifyATableOfContents-changeAFormattingPropertyUsedInFirstLevelTOCStyle.java\"><\/script>\n\n<p>It is also useful to note that any direct formatting of a paragraph (defined on the paragraph itself and not in the style) marked to be included in the <code>TOC<\/code> will be copied over in the entry in the TOC. For example, if the Heading 1 style is used to mark content for the <code>TOC<\/code> and this style has Bold formatting while the paragraph also has italic formatting directly applied to it. The resulting <code>TOC<\/code> entry will not be bold as that is part of style formatting however it will be italic as this is directly formatted on the paragraph.<\/p>\n<p>You can also control the formatting of the separators used between each entry and the page number. By default, this is a dotted line that is spread across to the page numbering using a tab character and a right tab stop lined up close to the right margin.<\/p>\n<p>Using the <code>Style<\/code> class retrieved for the particular <code>TOC<\/code> level you want to modify, you can also modify how these appear in the document.<\/p>\n<p>To change how this appears firstly <code>Style.ParagraphFormat<\/code> must be called to retrieve the paragraph formatting for the style. From this, the tab stops can be retrieved by calling <code>ParagraphFormat.TabStops<\/code> and the appropriate tab stop modified. Using this same technique the tab itself can be moved or removed altogether.<\/p>\n<p>The following code\u00a0example shows how to modify the position of the right tab stop in <code>TOC<\/code> related paragraphs.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-ModifyATableOfContents-modifyPositionOfRightTabStopInTOC.java\"><\/script>\n\n<h2 id=\"remove-a-table-of-contents-from-the-document\">Remove a Table of Contents from the Document<\/h2>\n<p>A table of contents can be removed from the document by removing all nodes found between the <code>FieldStart<\/code> and FieldEnd node of the <code>TOC<\/code> field.<\/p>\n<p>The code below demonstrates this. The removal of the <code>TOC<\/code> field is simpler than a normal field as we do not keep track of nested fields. Instead, we check the <code>FieldEnd<\/code> node is of type <code>FieldType.FieldTOC<\/code> which means we have encountered the end of the current TOC. This technique can be used in this case without worrying about any nested fields as we can assume that any properly formed document will have no fully nested <code>TOC<\/code> field inside another <code>TOC<\/code> field.<\/p>\n<p>Firstly the <code>FieldStart<\/code> nodes of each <code>TOC<\/code> are collected and stored. The specified <code>TOC<\/code> is then enumerated so all nodes within the field are visited and stored. The nodes are then removed from the document. The following code\u00a0example demonstrates how to remove a specified <code>TOC<\/code> from a document.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-RemoveATableOfContents-RemoveATableOfContents.java\"><\/script>\n\n<h2 id=\"extract-table-of-contents\">Extract Table of Contents<\/h2>\n<p>If you want to extract a table of contents from any Word document, the following code sample can be used.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-tableofcontents-ExtractTableOfContents-ExtractTableOfContents.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I insert a Table of Contents using Aspose.Words for Java?<br>\n<strong>A:<\/strong> Create a <code>Document<\/code> and a <code>DocumentBuilder<\/code>, then call <code>DocumentBuilder.insertTableOfContents(String switches)<\/code>. Pass the desired field switches (e.g., <code>\\\\o \\&quot;1-3\\&quot; \\\\h \\\\z \\\\u<\/code>) to control which headings are included and how the TOC is formatted.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> After editing the document, how can I refresh an existing TOC?<br>\n<strong>A:<\/strong> Call <code>document.updateFields()<\/code> followed by <code>document.updatePageLayout()<\/code>. The first method populates the TOC entries, and the second calculates and inserts the correct page numbers.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Which switch should I use to include custom heading styles in the TOC?<br>\n<strong>A:<\/strong> Use the <code>\\\\t<\/code> switch. Provide a list of custom style names and the level they should appear at, for example: <code>\\\\t \\&quot;MyCustomStyle,1,AnotherStyle,2\\&quot;<\/code>. Combine it with the <code>\\\\o<\/code> switch to also include built\u2011in headings.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I hide page numbers or make TOC entries clickable hyperlinks?<br>\n<strong>A:<\/strong> Add the <code>\\\\n<\/code> switch to omit page numbers for specified levels, and the <code>\\\\h<\/code> switch to generate hyperlink entries. For example: <code>\\\\o \\&quot;1-3\\&quot; \\\\h \\\\n \\&quot;1-1\\&quot;<\/code> will create hyperlinks and hide page numbers for level\u202f1.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What is the recommended way to delete a TOC from a document?<br>\n<strong>A:<\/strong> Locate the <code>FieldStart<\/code> nodes whose <code>FieldType<\/code> is <code>FieldType.FieldTOC<\/code>, collect all nodes up to the matching <code>FieldEnd<\/code>, and remove them from the document tree. This removes the field and its contents without affecting other fields.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Bookmarks in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-bookmarks\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-bookmarks\/","description":"\n        \n        \n        <p>Bookmarks identify in a Microsoft Word document the locations or fragments that you name and identify for future reference. For example, you might use a bookmark to identify text that you want to revise later. Instead of scrolling through the document to locate the text, you can go to it by using the Bookmark dialog box.<\/p>\n<p>With Aspose.Words, you can use bookmarks in reports or documents to insert some data into the bookmark or apply special formatting to its content. You can also use bookmarks to retrieve text from a certain location in your document.<\/p>\n<p>The actions that can be performed with bookmarks using Aspose.Words are the same as the ones you can perform using Microsoft Word. You can insert a new bookmark, delete, move to a bookmark, get or set a bookmark name, get or set text enclosed in it.<\/p>\n<h2 id=\"insert-a-bookmark\">Insert a Bookmark<\/h2>\n<p>Use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#startBookmark-java.lang.String\">startBookmark<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#endBookmark-java.lang.String\">endBookmark<\/a> to create a bookmark by marking its start and end, respectively. Do not forget to pass the same bookmark name to both methods. Bookmarks in a document can overlap and span any range. Badly formed bookmarks or bookmarks with duplicate names will be ignored when the document is saved.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nAll white spaces in the bookmarks were replaced with underscores. This restriction came from MS Word formats, since bookmarks in MS Word formats, like DOCX or DOC, cannot have white spaces. However, PDF allows such bookmarks. So now, if you need to use bookmarks in PDF, XPS or SWF outlines, you can use them with white spaces.\n<\/div>\n\n<p>The following code example shows how to create a new bookmark:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-bookmarks-CreateBookmark-CreateBookmark.java\"><\/script>\n\n<h2 id=\"obtain-bookmarks\">Obtain Bookmarks<\/h2>\n<p>Sometimes it is necessary to obtain a bookmark collection to iterate through bookmarks or for other purposes. Use the <strong>Node.getRange<\/strong> property exposed by any document node that returns a <strong>Range<\/strong> object representing the portion of the document contained in this node. Use this object to retrieve a <strong>BookmarkCollection<\/strong> and then use the collection indexer to get a specific bookmark.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of the following examples from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Bookmarks.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>The following code example shows how to obtain bookmarks from a bookmark collection:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-bookmarks-AccessBookmarks-AccessBookmarks.java\"><\/script>\n\n<p>The following code example shows how to get or set a bookmark name and text:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-bookmarks-BookmarkNameAndText-BookmarkNameAndText.java\"><\/script>\n\n<p>The following code example shows how to bookmark a table:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-bookmarks-BookmarkTable-BookmarkTable.java\"><\/script>\n\n<p>If you change the name of a bookmark to a name that already exists in the document, no error will be generated and only the first bookmark will be stored when you save the document.<\/p>\n<p>Note that some bookmarks in the document are assigned to form fields. Moving to such a bookmark and inserting text there inserts the text into the form field code. Although this will not invalidate the form field, the inserted text will not be visible because it becomes part of the field code.<\/p>\n<p>The following code example shows how to access columns of the bookmarked table:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-bookmarks-BookmarkTable-BookmarkTableColumns.java\"><\/script>\n\n<h2 id=\"move-to-a-bookmark\">Move to a Bookmark<\/h2>\n<p>If you need to insert rich content (not just plain text) into a bookmark, you should use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#moveToBookmark-java.lang.String\">moveToBookmark<\/a> to move the cursor to the bookmark and then use <strong>DocumentBuilder<\/strong> methods and properties to insert content.<\/p>\n<h2 id=\"show-hide-bookmark-content\">Show Hide Bookmark Content<\/h2>\n<p>The entire Bookmark (<em>including the bookmarked content<\/em>) can be encapsulated within the True part of the <code>IF<\/code> field using Aspose.Words. It can be in such a way that the <code>IF<\/code> field contains a nested Merge Field in the expression (<em>Left of Operator<\/em>) and depending upon the value of Merge Field, the <code>IF<\/code> field shows or hides the content of Bookmark in Word Document.<\/p>\n<p>The following code example shows how to show\/ hide bookmarks.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-bookmarks-ShowHideBookmarks-ShowHideBookmarks_call.java\"><\/script>\n\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-bookmarks-ShowHideBookmarks-ShowHideBookmarks.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I insert a new bookmark using Aspose.Words for Java?<br>\n<strong>A:<\/strong> Create a <code>DocumentBuilder<\/code> for your document, call <code>builder.startBookmark(&quot;MyBookmark&quot;)<\/code> at the start position, add the desired content, and then call <code>builder.endBookmark(&quot;MyBookmark&quot;)<\/code>. The same name must be used for both calls.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I retrieve the text stored inside an existing bookmark?<br>\n<strong>A:<\/strong> Obtain the <code>Bookmark<\/code> object from the document\u2019s bookmark collection:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"n\">Document<\/span> <span class=\"n\">doc<\/span> <span class=\"o\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Document<\/span><span class=\"o\">(<\/span><span class=\"s\">&#34;input.docx&#34;<\/span><span class=\"o\">);<\/span>\n<span class=\"n\">Bookmark<\/span> <span class=\"n\">bookmark<\/span> <span class=\"o\">=<\/span> <span class=\"n\">doc<\/span><span class=\"o\">.<\/span><span class=\"na\">getRange<\/span><span class=\"o\">().<\/span><span class=\"na\">getBookmarks<\/span><span class=\"o\">().<\/span><span class=\"na\">get<\/span><span class=\"o\">(<\/span><span class=\"s\">&#34;MyBookmark&#34;<\/span><span class=\"o\">);<\/span>\n<span class=\"n\">String<\/span> <span class=\"n\">text<\/span> <span class=\"o\">=<\/span> <span class=\"n\">bookmark<\/span><span class=\"o\">.<\/span><span class=\"na\">getText<\/span><span class=\"o\">();<\/span>\n<\/code><\/pre><\/div><p>The <code>getText()<\/code> method returns the full text enclosed by the bookmark.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to rename a bookmark after it has been created?<br>\n<strong>A:<\/strong> Yes. After retrieving the <code>Bookmark<\/code> object, call <code>bookmark.setName(&quot;NewName&quot;)<\/code>. Ensure the new name is unique; if a duplicate exists, only the first bookmark with that name will be saved.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I move the cursor to a bookmark to insert rich content?<br>\n<strong>A:<\/strong> Use <code>DocumentBuilder.moveToBookmark(&quot;MyBookmark&quot;)<\/code>. Once the builder\u2019s cursor is positioned, you can insert paragraphs, tables, images, etc., just as with any other <code>DocumentBuilder<\/code> operation.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I conditionally show or hide the content of a bookmark?<br>\n<strong>A:<\/strong> Wrap the bookmark inside an <code>IF<\/code> field that evaluates a merge field or custom document variable. When the condition is true, the bookmark\u2019s content is displayed; otherwise, it is hidden. This technique is demonstrated in the \u201cShow Hide Bookmark Content\u201d example.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Tables in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-tables\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-tables\/","description":"\n        \n        \n        <p>A <strong>table<\/strong> in a document is a great way to structure similar data. That is why tables are a common content formatting element and are supported by most formats in one form or another.<\/p>\n<p>Tables allow you to organize and clearly display large amounts of informationin a grid-type structure with rows and columns. They are also often used as a page layout tool and a better alternative for displaying tabbed data (with tab stops) as they allow more control over the design and layout of the content. This way you can even lay out content that needs to be stored in a fixed position using a borderless table.<\/p>\n<p>The table consists of such elements as <strong>Cell<\/strong>, <strong>Row<\/strong>, and <strong>Column<\/strong>. This is a concept that is common to all tables in general, regardless of which editor or document format the table was created in. For example, a table created in Microsoft Word or a table created in an HTML document would conform to the concept of cells, rows, and columns.<\/p>\n<p>Aspose.Words fully supports tables and high fidelity table rendering. You can freely edit, change, add, and remove tables and content in tables. In addition to plain text, other content can be placed in table cells, such as images, fields, or even other tables.<\/p>\n\n      "},{"title":"Java: Working with Lists in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-lists\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-lists\/","description":"\n        \n        \n        <p>A list in a Microsoft Word document is a set of list formatting properties. Lists can be used in your documents to format, arrange, and emphasize text. Lists are a great way to organize data in documents, and they make it easier for readers to understand key points.<\/p>\n<p>Each list can have up to 9 levels and formatting properties, such as number style, start value, indent, tab position, and others are defined separately for each level.<\/p>\n<p>This article describes programmatically working with lists using Aspose.Words.<\/p>\n<h2 id=\"creating-lists-by-applying-list-formatting\">Creating Lists by Applying List Formatting<\/h2>\n<p>Aspose.Words allows the easy creation of lists by applying list formatting. <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> provides the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getListFormat\">ListFormat<\/a> property that returns a <strong>ListFormat<\/strong> object. This object has several methods to start and end a list and to increase\/decrease the indent.\u00a0There are two general types of lists in Microsoft Word: bulleted and numbered:<\/p>\n<ul>\n<li>To start a bulleted list, call\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/listformat\/#applyBulletDefault\">ListFormat.ApplyBulletDefault<\/a><\/li>\n<li>To start a numbered list, call\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/listformat\/#applyNumberDefault\">ListFormat.ApplyNumberDefault<\/a><\/li>\n<\/ul>\n<p>The bullet or number and formatting are added to the current paragraph and all further paragraphs created using\u00a0<strong>DocumentBuilder<\/strong>\u00a0until\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/listformat\/#removeNumbers\">RemoveNumbers<\/a>\u00a0is called to stop bulleted list formatting.<\/p>\n<p>In Word documents, lists may consist of up to nine levels. List formatting for each level specifies what bullet or number is used, left indent, space between the bullet and text etc. The following methods change the list level and apply the new level&rsquo;s formatting properties:<\/p>\n<ul>\n<li>To increase the list level of the current paragraph by one level, call\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/listformat\/#listIndent\">ListFormat.ListIndent<\/a><\/li>\n<li>To decrease the list level of the current paragraph by one level, call\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/listformat\/#listOutdent\">ListFormat.ListOutdent<\/a><\/li>\n<\/ul>\n<p>The methods change the list level and apply the formatting properties of the new level.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can also use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/listformat\/#getListLevelNumber\">ListLevelNumber<\/a> property to get or set the list level for the paragraph. The list levels are numbered 0 to 8.\n<\/div>\n\n<p>The following code example shows how to build a multilevel list:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderSetMultilevelListFormatting-DocumentBuilderSetMultilevelListFormatting.java\"><\/script>\n\n<h2 id=\"specify-formatting-for-a-list-level\">Specify Formatting for a List Level<\/h2>\n<p>List-level objects are created automatically when a list is created. Use the properties and methods of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words.listlevel\/\">ListLevel<\/a> class to control the formatting of individual levels of a list.<\/p>\n<h2 id=\"restart-list-for-each-section\">Restart List for each Section<\/h2>\n<p>You can restart a list for each section using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words.list\/#isrestartateachsection\">IsRestartAtEachSection<\/a> property. Note that this option is supported only in RTF, DOC and DOCX document formats. This option will be written to DOCX only if OoxmlCompliance is higher then Ecma376.<\/p>\n<p>The following code example shows how to create a list and restart it for each section:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Lists-WorkingWithList-SetRestartAtEachSection.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I start a bulleted list using Aspose.Words for Java?<br>\n<strong>A:<\/strong> Use the <code>DocumentBuilder<\/code> object, access its <code>ListFormat<\/code> property, and call <code>applyBulletDefault()<\/code>. The bullet formatting will be applied to the current paragraph and all subsequent paragraphs until <code>removeNumbers()<\/code> is called.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I create a multilevel numbered list and control each level\u2019s appearance?<br>\n<strong>A:<\/strong> After starting a list with <code>applyNumberDefault()<\/code>, use <code>ListLevel<\/code> objects (available via <code>builder.getListFormat().getList().getListLevels()<\/code>) to set properties such as <code>numberStyle<\/code>, <code>font<\/code>, <code>alignment<\/code>, and <code>tabPosition<\/code> for each level (0\u20118). Adjust the level with <code>listIndent()<\/code> and <code>listOutdent()<\/code> as needed.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to restart numbering for each new section in a document?<br>\n<strong>A:<\/strong> Yes. Set the <code>IsRestartAtEachSection<\/code> property of the <code>List<\/code> object to <code>true<\/code>. This works for RTF, DOC, and DOCX formats and is written to DOCX only when the document\u2019s <code>OoxmlCompliance<\/code> is higher than <code>Ecma376<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I retrieve or change the current list level of a paragraph?<br>\n<strong>A:<\/strong> Use the <code>getListLevelNumber()<\/code> method of <code>ListFormat<\/code> to read the level, and <code>setListLevelNumber(int level)<\/code> to change it. Levels are zero\u2011based, ranging from 0 to 8.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Paragraphs in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-paragraphs\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-paragraphs\/","description":"\n        \n        \n        <p>A paragraph is a set of characters combined into a logical block and ending with a special character \u2013 a <em>paragraph break<\/em>. In Aspose.Words, a paragraph is represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraph\/\">Paragraph<\/a> class.<\/p>\n<h2 id=\"inserting-a-paragraph\">Inserting a Paragraph<\/h2>\n<p>To insert a new paragraph into the document, in fact, you need to insert a paragraph break character into it. <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#writeln\">DocumentBuilder.Writeln<\/a> inserts not only a string of text into the document, but also adds a paragraph break.<\/p>\n<p>The current font formatting is also specified by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getFont\">Font<\/a> property, and the current paragraph formatting is determined by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getParagraphFormat\">ParagraphFormat<\/a> property. In the next section, we will go into more detail about paragraph formatting.<\/p>\n<p>The following code example shows how to insert a paragraph into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-DocumentBuilderInsertParagraph.java\"><\/script>\n\n<h2 id=\"format-paragraph\">Format Paragraph<\/h2>\n<p>Current paragraph formatting is represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/\">ParagraphFormat<\/a> object that is returned by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getParagraphFormat\">ParagraphFormat<\/a> property. This object encapsulates various paragraph formatting properties available in Microsoft Word. You can easily reset a paragraph&rsquo;s formatting to its default \u2013 Normal style, left-aligned, no indentation, no spacing, no borders, no shading \u2013 by calling <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/#clearFormatting\">ClearFormatting<\/a>.<\/p>\n<p>The following code example shows how to set paragraph formatting:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-DocumentBuilderSetParagraphFormatting.java\"><\/script>\n\n<h2 id=\"apply-paragraph-style\">Apply Paragraph Style<\/h2>\n<p>Some formatting objects like Font or ParagraphFormat support styles. A single built-in or user-defined style is represented by a <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/style\/\">Style<\/a> object that contains the corresponding style properties like name, base style, font and paragraph formatting of the style, and so on.<\/p>\n<p>Furthermore, a\u00a0<strong>Style<\/strong>\u00a0object provides the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/style\/#getStyleIdentifier\">StyleIdentifier<\/a>\u00a0property that returns a locale-independent style identifier represented by a\u00a0<strong>StyleIdentifier<\/strong>\u00a0enumeration value. The point is that the names of built-in styles in Microsoft Word are localized for different languages. Using a style identifier, you can find the correct style regardless of the document language. The enumeration values correspond to the Microsoft Word built-in styles such as <em>Normal<\/em>, <em>Heading 1<\/em>, <em>Heading 2<\/em>, etc. All user-defined styles are assigned the\u00a0<strong>StyleIdentifier.User value<\/strong>.<\/p>\n<p>The following code example shows how to apply a paragraph style:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-DocumentBuilderApplyParagraphStyle.java\"><\/script>\n\n<h2 id=\"insert-style-separator-to-put-different-paragraph-styles\">Insert Style Separator to Put Different Paragraph Styles<\/h2>\n<p>The style separator can be added to the end of a paragraph using the Ctrl + Alt + Enter Keyboard Shortcut into MS Word. This feature allows for two different paragraph styles used in one logical printed paragraph.\u00a0If you want to some text from the beginning of a particular heading to appear in a Table of Contents but don&rsquo;t want the entire heading in the Table of Contents, you can use this feature.<\/p>\n<p>The following code example shows how to insert a style separator to accommodate different paragraph styles:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-ParagraphInsertStyleSeparator.java\"><\/script>\n\n<h2 id=\"apply-borders-and-shading-to-a-paragraph\">Apply Borders and Shading to a Paragraph<\/h2>\n<p>Borders in Aspose.Words are represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/bordercollection\/\">BorderCollection<\/a> class \u2013\u00a0this is a collection of <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/border\/\">Border<\/a> objects that are accessed by index or by border type. The <code>Border<\/code> type is represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/bordertype\/\">BorderType<\/a> enumeration. Some values of the enumeration are applicable to several or only one document element. For example, <strong>BorderType.Bottom<\/strong> is applicable to a paragraph or table cell while <strong>BorderType.DiagonalDown<\/strong> specifies the diagonal border in a table cell only.<\/p>\n<p>Both the border collection and each separate border have similar attributes like color, line style, line width, distance from the text, and optional shadow. They are represented by properties of the same name. You can achieve different border types by combining the property values. In addition, both\u00a0<strong>BorderCollection<\/strong>\u00a0and\u00a0<strong>Border<\/strong>\u00a0objects allow you to reset these values to default by calling the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/border\/#clearFormatting\">ClearFormatting<\/a>\u00a0method.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that when border properties are reset to default values, the border is invisible.\n<\/div>\n\n<p>Aspose.Words also has the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shading\/\">Shading<\/a>\u00a0class contains shading attributes for document elements. You can set the desired shading texture and the colors that are applied to the background and foreground of the element.<\/p>\n<p>The shading texture is set with the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/textureindex\/\">TextureIndex<\/a>\u00a0enumeration value that allows the application of various patterns to the\u00a0<strong>Shading<\/strong>\u00a0object. For example, to set a background color for a document element, use the <code>TextureIndex.TextureSolid<\/code>\u00a0value and set the foreground shading color as appropriate. The code example given below shows how to apply borders and shading to a paragraph.<\/p>\n<p>The following code example shows how to apply borders and shading to a paragraph:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-DocumentBuilderApplyBordersAndShadingToParagraph.java\"><\/script>\n\n\n      "},{"title":"Java: Working with Hyphenation in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-hyphenation\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-hyphenation\/","description":"\n        \n        \n        <p>Sometimes it is necessary to use hyphenation for a more compact arrangement of text in a document. At the same time, it is important to understand that the specifics of word hyphenation may differ for each language.<\/p>\n<p>At the present time, hyphenation is not used as often as it used to be, especially in English texts. Nevertheless, the use of this feature can have a serious impact on user documents \u2013 hyphenation affects the layout and, as a result, the appearance of the output files, for example, in PDF format.<\/p>\n<p>For correct splitting of words, language-specific hyphenation dictionaries are used. Aspose.Words uses advanced algorithms to work with such dictionaries and allows you to get the same hyphenation as in Microsoft Word.<\/p>\n<h2 id=\"hyphenation-dictionaries\">Hyphenation Dictionaries<\/h2>\n<p>Since different languages use different norms and rules for word hyphenation, the optimal solution for correct hyphenation is to use special dictionaries. Aspose.Words uses OpenOffice dictionaries.<\/p>\n<p>For spell checking, OpenOffice uses the <a href=\"https:\/\/hunspell.github.io\/\">Hunspell library<\/a>, which is a generalization of TeX\u2019s hyphenation algorithm. This algorithm allows for automatic non-standard hyphenation using competing standard and custom hyphenation patterns. Hunspell uses the <a href=\"https:\/\/github.com\/hunspell\/hyphen\">Hyphen<\/a> for hyphenation.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nHyphenation dictionaries can be taken from the <a href=\"https:\/\/github.com\/LibreOffice\/dictionaries\">LibreOffice dictionaries GitHub<\/a>. For example, <a href=\"https:\/\/github.com\/LibreOffice\/dictionaries\/blob\/master\/en\/hyph_en_US.dic\">en-US hyphenation dictionary<\/a>.\n<\/div>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nAs Microsoft Word uses dictionaries other than OpenOffice dictionaries to perform hyphenation, the hyphenation of some words defined by OpenOffice dictionaries may differ from the Microsoft Word hyphenation. For this reason, sometimes we have to advise customers to add the necessary patterns to their dictionaries in order to fix the hyphenation of particular words.\n<\/div>\n\n<h2 id=\"hyphenation-algorithm\">Hyphenation Algorithm<\/h2>\n<p>Aspose.Words implements <a href=\"https:\/\/github.com\/hunspell\/hyphen\/blob\/master\/README.hyphen\">the TeX hyphenation algorithm<\/a> and can reuse OpenOffice hyphenation dictionaries.<\/p>\n<p>The following features of Aspose.Words algorithms should be taken into account:<\/p>\n<ul>\n<li>Hyphenation distance parameters (LEFTHYPHENMIN, RIGHTHYPHENMIN, COMPOUNDLEFTHYPHENMIN, COMPOUNDRIGHTHYPHENMIN) specified in the hyphenation dictionary are ignored. Aspose.Words uses its own set of distance parameters depending on the document compatibility mode.<\/li>\n<li>The hyphenation algorithm in Aspose.Words supports <a href=\"https:\/\/github.com\/hunspell\/hyphen\/blob\/master\/README.compound\">composite hyphenation<\/a>. However, Aspose.Words splits character sequences containing mixed alphabetic and non-alphabetic characters into alphabetic-only parts (words) and hyphenates them separately.\nNote that Microsoft Word logic of hyphenation of compound words depends on document compatibility mode.<\/li>\n<li>The hyphenation algorithm in Aspose.Words does not implement the <a href=\"https:\/\/github.com\/hunspell\/hyphen\/blob\/master\/doc\/tb87nemeth.pdf\">non-standard hyphenation<\/a>. Non-standard patterns are ignored.<\/li>\n<\/ul>\n<h2 id=\"loading-hyphenation-dictionaries\">Loading Hyphenation Dictionaries<\/h2>\n<p>To use the hyphenation feature, first register a hyphenation dictionary.The following code example shows how to load hyphenation dictionaries for the specified languages from a file:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-rendering_printing-HyphenateWords-LoadHyphenationDictionaryFromFile.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the template file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Rendering.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>The following code example shows how to load hyphenation dictionaries for the specified language from a stream:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-rendering_printing-HyphenateWords-LoadHyphenationDictionaryFromStream.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the template file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Rendering.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>As an alternative to pre-registering hyphenation dictionaries, it is possible to register only required hyphenation dictionaries \u201cby request\u201d. To achieve that, implement the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/ihyphenationcallback\/\">IHyphenationCallback<\/a> interface and use the static callback <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/hyphenation\/#getCallback\">Callback<\/a>.<\/p>\n<p>The following code example shows how to implement the <strong>IHyphenationCallback<\/strong> interface:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-rendering_printing-HyphenateWords-HyphenationCallback.java\"><\/script>\n\n<h2 id=\"impact-of-hyphenation-on-layout\">Impact of Hyphenation on Layout<\/h2>\n<p>When breaking text into lines, Aspose.Words checks each word whether it fits entirely into the current line. If another word is too long to fit at the end of the line, by default Aspose.Words moves it to the beginning of the next line instead of hyphenating it.<\/p>\n<p>However, the hyphenation feature can be used in Aspose.Words to insert hyphens into words to eliminate gaps in justified text or to maintain an even line length in narrow columns. This can obviously affect the number of lines and therefore the number of pages. In other words, using the hyphenation function affects the document layout.<\/p>\n<h2 id=\"hyphenation-and-justification-hj\">Hyphenation and Justification (H&amp;J)<\/h2>\n<p>Microsoft Word has complex logic for choosing a breakpoint if text is justified and hyphenation is enabled. In short, Microsoft Word may prefer to shrink or stretch spaces to avoid line hyphenation. Most probably this logic is based on <a href=\"https:\/\/www.eprg.org\/G53DOC\/pdfs\/knuth-plass-breaking.pdf\">Knuth&rsquo;s article<\/a>.<\/p>\n<p>Aspose.Words implements its own H&amp;J algorithm that gives the same result as Microsoft Word and provides identical line breaking in the output document.<\/p>\n<h2 id=\"see-also\">See Also<\/h2>\n<ul>\n<li><a href=\"https:\/\/github.com\/hunspell\/hyphen\/blob\/master\/README\">Hyphen \u2013 hyphenation library<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/hunspell\/hyphen\/blob\/master\/README.nonstandard\">Non-standard hyphenation<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/hunspell\/hyphen\/blob\/master\/doc\/tb87nemeth.pdf\">Automatic non-standard hyphenation in Open Office<\/a><\/li>\n<\/ul>\n\n      "},{"title":"Java: Working with Fonts in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-fonts\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-fonts\/","description":"\n        \n        \n        <p>A font is a set of characters with a certain size, color, and design. Aspose.Words allows you to work with fonts using various font-related classes, including the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/\">Font<\/a> class.<\/p>\n<h2 id=\"font-formatting\">Font Formatting<\/h2>\n<p>Current font formatting is represented by a <strong>Font<\/strong> object returned by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#getFont\">Font<\/a> property. The <strong>Font<\/strong> class contains a wide variety of font properties possible in Microsoft Word.<\/p>\n<p>The following code example shows how to set font formatting:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkWithDocumentBuilder-SetFontFormatting.java\"><\/script>\n\n<p>Fill properties now are also available for fonts to set fill formatting of text. It gives an ability to change, for example, the foreground color or transparency of text fill.<\/p>\n<h2 id=\"getting-font-line-spacing\">Getting Font Line Spacing<\/h2>\n<p>The line spacing of a font is the vertical distance between the baselines of two consecutive lines of text. Thus, the line spacing includes the blank space between lines along with the height of the character itself.<\/p>\n<p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/#getLineSpacing\">LineSpacing<\/a> property was introduced in the <strong>Font<\/strong> class to obtain this value as shown in the example given below:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-GetFontLineSpacing-GetFontLineSpacing.java\"><\/script>\n\n<h2 id=\"fontemphasismark\">Font\u00a0EmphasisMark<\/h2>\n<p>The <strong>Font<\/strong> class provides <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/font\/#getEmphasisMark\">EmphasisMark<\/a> property to get or set EmphasisMark enumeration values to be applied in the formatting.<\/p>\n<p>The following code example shows how to set the <strong>EphasisMark<\/strong> property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkWithDocumentBuilder-SetFontEmphasisMark.java\"><\/script>\n\n\n      "},{"title":"Java: Asian Typography in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-asian-typography\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-asian-typography\/","description":"\n        \n        \n        <p>Asian Typography is a set of options for text paragraphs in documents written in Asian languages.<\/p>\n<p>Aspose.Words supports Asian Typography using the <a href=\"https:\/\/reference.aspose.com\/words\/net\/aspose.words\/paragraphformat\/\">ParagraphFormat<\/a> class and some of its properties.<\/p>\n<h2 id=\"automatically-adjust-space-between-asian-and-latin-text-or-numbers\">Automatically Adjust Space between Asian and Latin Text or Numbers<\/h2>\n<p>If you are designing a template with both East Asian and Latin text and  want to enhance the appearance of your form template by controlling the spaces between both types of text, you can configure your form template to automatically adjust the spaces between these two types of text. To achieve this, you can use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/#getAddSpaceBetweenFarEastAndAlpha\">AddSpaceBetweenFarEastAndAlpha<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/#getAddSpaceBetweenFarEastAndDigit\">AddSpaceBetweenFarEastAndDigit<\/a> properties of the <code>ParagraphFormat<\/code> class.<\/p>\n<p>The following code example shows how to use <strong>AddSpaceBetweenFarEastAndAlpha<\/strong> and <strong>AddSpaceBetweenFarEastAndDigit<\/strong> properties:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-DocumentBuilderSetSpaceBetweenAsianAndLatinText.java\"><\/script>\n\n<h2 id=\"set-line-break-options\">Set Line Break Options<\/h2>\n<p>The Asian Typography tab of the paragraph properties dialog box in Microsoft Word has line break group. The options of this group can be set using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/#getFarEastLineBreakControl\">FarEastLineBreakControl<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/#getWordWrap\">WordWrap<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/paragraphformat\/#getHangingPunctuation\">HangingPunctuation<\/a> properties of the <strong>ParagraphFormat<\/strong> class.<\/p>\n<p>The following code example shows how to use these properties:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-SetAsianTypographyLinebreakGroupProp.java\"><\/script>\n\n<h2 id=\"change-asian-paragraph-spacing-and-indents\">Change Asian Paragraph Spacing and Indents<\/h2>\n<p>The following code example shows how to change Asian paragraph spacing and indents:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithParagraphs-ChangeAsianParagraphSpacingandIndents.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I enable automatic spacing between Asian characters and Latin letters or numbers?<br>\n<strong>A:<\/strong> Set <code>ParagraphFormat.AddSpaceBetweenFarEastAndAlpha<\/code> to <code>true<\/code> for spacing with Latin letters and <code>ParagraphFormat.AddSpaceBetweenFarEastAndDigit<\/code> to <code>true<\/code> for spacing with digits. These properties can be applied to a <code>Paragraph<\/code> or globally via a <code>DocumentBuilder<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Which properties control line\u2011break behavior for Asian text?<br>\n<strong>A:<\/strong> Use <code>ParagraphFormat.FarEastLineBreakControl<\/code> to prevent line breaks within Asian words, <code>ParagraphFormat.WordWrap<\/code> to enable\/disable wrapping, and <code>ParagraphFormat.HangingPunctuation<\/code> to control hanging punctuation for East Asian scripts.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I adjust spacing and indents specifically for Asian paragraphs?<br>\n<strong>A:<\/strong> Modify <code>ParagraphFormat.FirstLineIndent<\/code>, <code>LeftIndent<\/code>, <code>RightIndent<\/code>, and <code>SpaceAfter<\/code>\/<code>SpaceBefore<\/code> while the <code>ParagraphFormat<\/code> is set to an Asian language context. The examples in this article demonstrate these settings.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Are there any font considerations when working with Asian typography?<br>\n<strong>A:<\/strong> Aspose.Words uses the fonts installed on the system. Ensure the required CJK fonts (e.g., SimSun, MS Mincho) are available, or use <code>FontSettings<\/code> to load custom fonts so that Asian characters render correctly.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I disable Asian typography features for a document that contains only Latin text?<br>\n<strong>A:<\/strong> Yes. Set the three properties (<code>AddSpaceBetweenFarEastAndAlpha<\/code>, <code>AddSpaceBetweenFarEastAndDigit<\/code>, <code>FarEastLineBreakControl<\/code>) to <code>false<\/code> or leave them at their default values; Aspose.Words will then treat the text as regular Latin script.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Linked TextBoxes in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-linked-textboxes\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-linked-textboxes\/","description":"\n        \n        \n        <p>In Aspose.Words, the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/textbox\/\">TextBox<\/a> class is used to specify how a text is displayed inside a shape. It provides a public property named as Parent\u00a0to get the parent shape for the text box to allow the customer to find linked <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/\">Shape<\/a> from linked <strong>TextBox<\/strong>.<\/p>\n<h2 id=\"create-a-link\">Create A Link<\/h2>\n<p>The <strong>TextBox<\/strong> class provides the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/textbox\/#isValidLinkTarget-com.aspose.words.TextBox\">IsValidLinkTarget<\/a> method in order to check whether the\u00a0<strong>TextBox<\/strong> can be linked to the target <strong>Textbox<\/strong>.<\/p>\n<p>The following code example shows how to check if the <code>TextBox<\/code> can be linked to the target Textbox:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-LinkedTextboxes-WorkingWithLinkedTextboxes-CreateALink.java\"><\/script>\n\n<h2 id=\"check-textbox-sequence\">Check TextBox Sequence<\/h2>\n<p>There are several ways to display text in a shape. The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#getTextBox\">TextBox<\/a> can be the Head, Middle, or Tail of a sequence.<\/p>\n<p>The following code example shows how to check\u00a0if <strong>TextBox<\/strong> is a Head, Tail, or Middle of the sequence:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-LinkedTextboxes-WorkingWithLinkedTextboxes-CheckSequence.java\"><\/script>\n\n<h2 id=\"break-a-link\">Break a Link<\/h2>\n<p>Using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words.textbox\/#breakForwardLink\">BreakForwardLink<\/a> method you can break the link to the next <strong>TextBox<\/strong>.<\/p>\n<p>The following code example shows how to break a link for a <strong>TextBox<\/strong>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-LinkedTextboxes-WorkingWithLinkedTextboxes-BreakALink.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I check if a <code>TextBox<\/code> can be linked to another <code>TextBox<\/code>?<br>\n<strong>A:<\/strong> Call <code>textBox.isValidLinkTarget(targetTextBox)<\/code>. The method returns <code>true<\/code> when the two text boxes belong to the same document and satisfy the linking rules; otherwise it returns <code>false<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I obtain the shape that contains a linked <code>TextBox<\/code>?<br>\n<strong>A:<\/strong> Use the <code>textBox.getParent()<\/code> property. It returns the parent <code>Shape<\/code> object, allowing you to access shape\u2011level properties or navigate to the linked shape.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I determine whether a <code>TextBox<\/code> is the head, middle, or tail of a linked sequence?<br>\n<strong>A:<\/strong> The <code>TextBox<\/code> class provides <code>isHead()<\/code>, <code>isMiddle()<\/code>, and <code>isTail()<\/code> methods. Checking these methods tells you the position of the text box within the linked chain.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I break a forward link from a <code>TextBox<\/code>?<br>\n<strong>A:<\/strong> Invoke <code>textBox.breakForwardLink()<\/code>. This removes the link to the next text box in the sequence, leaving the current box isolated.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I link a <code>TextBox<\/code> to a shape that is not a <code>TextBox<\/code>?<br>\n<strong>A:<\/strong> No. Linking is only supported between <code>TextBox<\/code> objects. Attempting to link to other shape types will cause <code>isValidLinkTarget<\/code> to return <code>false<\/code> and the link operation will be ignored.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Comments in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-comments\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-comments\/","description":"\n        \n        \n        \n\n<div class=\"alert alert-primary\" role=\"alert\">\n\n<p><strong>Try online<\/strong><\/p>\n<p>You can try this functionality with our <a href=\"https:\/\/products.aspose.app\/words\/annotation\">Free online remove annotations<\/a>.<\/p>\n\n<\/div>\n\n<p>Aspose.Words allows users to work with comments \u2013 comments in a document in Aspose.Words are represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/comment\/\">Comment<\/a> class. Also use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/commentrangestart\/\">CommentRangeStart<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/commentrangeend\/\">CommentRangeEnd<\/a> classes to specify the region of text that should be associated with a comment.<\/p>\n<h2 id=\"add-a-comment\">Add a Comment<\/h2>\n<p>Aspose.Words allows you to add comments in several ways:<\/p>\n<ol>\n<li>Using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/comment\/\">Comment<\/a> class<\/li>\n<li>Using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/commentrangestart\/\">CommentRangeStart<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/commentrangeend\/\">CommentRangeEnd<\/a> classes<\/li>\n<\/ol>\n<p>The following code example shows how to add a comment to a paragraph using the <strong>Comment<\/strong> class:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-AddComments-AddComments.java\"><\/script>\n\n<p>The following code example shows how to add a comment to a paragraph using a region of text and the <strong>CommentRangeStart<\/strong> and <strong>CommentRangeEnd<\/strong> classes:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-AnchorComment-AnchorComment.java\"><\/script>\n\n<h2 id=\"extract-or-remove-comments\">Extract or Remove Comments<\/h2>\n<p>Using Comments in a Word document (in addition to Track Changes) is a common practice when reviewing documents, particularly when there are multiple reviewers. There can be situations where the only thing you need from a document is the comments. Say you want to generate a list of review findings, or perhaps you have collected all the useful information from the document and you simply want to remove unnecessary comments. You may want to view or remove the comments of a particular reviewer.<\/p>\n<p>In this sample, we are going to look at some simple methods for both gathering information from the comments within a document and for removing comments from a document. Specifically, we&rsquo;ll cover how to:<\/p>\n<ul>\n<li>Extract all the comments from a document or only the ones made by a particular author.<\/li>\n<li>Remove all the comments from a document or only from a particular author.<\/li>\n<\/ul>\n<h3 id=\"how-to-extract-or-remove-comments\">How to Extract or Remove Comments<\/h3>\n<p>The code in this sample is quite simple and all methods are based on the same approach. A comment in a Word document is represented by a <code>Comment<\/code> object in the Aspose.Words document object model. To collect all the comments in a document use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getChildNodes\">getChildNodes<\/a> method with the first parameter set to <code>NodeType.Comment<\/code>. Make sure that the second parameter of the <strong>getChildNodes<\/strong> method is set to true: this forces the <strong>getChildNodes<\/strong> to select from all child nodes recursively, rather than only collecting the immediate children.<\/p>\n<p>To illustrate how to extract and remove comments from a document, we will go through the following steps:<\/p>\n<ol>\n<li>Open a Word document using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/\">Document<\/a> class<\/li>\n<li>Get all comments from the document into a collection<\/li>\n<li>To extract comments:\n<ol>\n<li>Go through the collection using the for the operator<\/li>\n<li>Extract and list the author name, date &amp; time and text of all comments<\/li>\n<li>Extract and list the author name, date &amp; time and text of comments written by a specific author, in this case, the author <code>ks<\/code><\/li>\n<\/ol>\n<\/li>\n<li>To remove comments:\n<ol>\n<li>Go backwards through the collection using the for the operator<\/li>\n<li>Remove comments<\/li>\n<\/ol>\n<\/li>\n<li>Save the changes.<\/li>\n<\/ol>\n<p>We are going to use the following Word document for this exercise:<\/p>\n<p><img src=\"extract-remove-comments-aspose-words-java-1.png\" alt=\"extract-remove-comments-aspose-words-java-1\"><\/p>\n<p>As you can see, it contains several Comments from two authors with the initials \u201cpm\u201d and \u201cks\u201d.<\/p>\n<h3 id=\"how-to-extract-all-comments\">How to Extract All Comments<\/h3>\n<p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getChildNodes\">getChildNodes<\/a> method is very useful and you can use it every time you need to get a list of document nodes of any type. The resulting collection does not create an immediate overhead because the nodes are selected into this collection only when you enumerate or access items in it.<\/p>\n<p>The following code example shows how to extract the author name, date&amp;time and text of all comments in the document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-ProcessComments-extractComments.java\"><\/script>\n\n<h3 id=\"how-to-extract-comments-of-a-specified-author\">How to Extract Comments of a Specified Author<\/h3>\n<p>After you have selected Comment nodes into a collection, all you have to do is extract the information you need. In this sample, the author&rsquo;s initials, date, time and the plain text of the comment is combined into one string; you could choose to store it in some other ways instead.<\/p>\n<p>The overloaded method that extracts the Comments from a particular author is almost the same, it just checks the author\u2019s name before adding the info into the array.<\/p>\n<p>The following code example shows how to extract the author name, date&amp;time and text of the comments by the specified author:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-ProcessComments-extractComments_Author.java\"><\/script>\n\n<h3 id=\"how-to-remove-comments\">How to Remove Comments<\/h3>\n<p>If you are removing all comments, there is no need to move through the collection deleting comments one by one; you can remove them by calling <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/nodecollection\/#clear\">clear<\/a> on the comments collection.<\/p>\n<p>The following code example shows how to remove all comments in the document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-ProcessComments-removeComments.java\"><\/script>\n\n<p>When you need to selectively remove comments, the process becomes more similar to the code we used for comment extraction.<\/p>\n<p>The following code example shows how to remove comments by the specified author:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-ProcessComments-removeComments_Author.java\"><\/script>\n\n<p>The main point to highlight here is the use of the for operator. Unlike the simple extraction, here you want to delete a comment. A suitable trick is to iterate the collection backwards from the last Comment to the first one. The reason for this if you start from the end and move backwards, the index of the preceding items remains unchanged, and you can work your way back to the first item in the collection.<\/p>\n<p>The following code example shows the methods for the comments extraction and removal:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-ProcessComments-ProcessComments.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of this example from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/src\/main\/resources\/com\/aspose\/words\/examples\/programming_documents\/comments\/ProcessComments\/TestFile.doc\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>When launched, the sample displays the following results. First, it lists all comments by all authors, then it lists comments by the selected author only. Finally, the code removing all comments.<\/p>\n<p><img src=\"extract-remove-comments-aspose-words-java-2.png\" alt=\"extract-remove-comments-aspose-words-java-2\"><\/p>\n<p>The output Word document has now comments removed from it:<\/p>\n<p><img src=\"extract-remove-comments-aspose-words-java-3.png\" alt=\"extract-remove-comments-aspose-words-java-3\"><\/p>\n<h3 id=\"how-to-remove-text-between-commentrangestart-and-commentrangeend\">How to Remove Text between CommentRangeStart and CommentRangeEnd<\/h3>\n<p>Using Aspose.Words you can also remove comments between the CommentRangeStart and CommentRangeEnd nodes.<\/p>\n<p>The following code example shows how to remove text between\u00a0CommentRangeStart and CommentRangeEnd:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-RemoveCommentRegionText-RemoveCommentRegionText.java\"><\/script>\n\n<h2 id=\"add-or-remove-comments-reply\">Add or Remove Comment&rsquo;s Reply<\/h2>\n<p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/comment\/#addReply-java.lang.String-java.lang.String-java.util.Date-java.lang.String\">addReply<\/a> method adds a reply to this comment. Please note that due to the existing MS Office limitations only one (1) level of replies is allowed in the document. An exception of type InvalidOperationException will be raised if this method is called on the existing Reply comment.<\/p>\n<p>You can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/comment\/#removeReply-com.aspose.words.Comment\">removeReply<\/a> method to remove the specified reply to this comment.<\/p>\n<p>The following code example shows how to add a reply to a comment and remove a comment&rsquo;s reply:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-AddRemoveCommentReply-AddRemoveCommentReply.java\"><\/script>\n\n<h2 id=\"read-comments-reply\">Read Comment&rsquo;s Reply<\/h2>\n<p>Aspose.Words support to read the reply of a Comment. The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/comment\/#getReplies\">Replies<\/a> property returns a collection of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/comment\/\">Comment<\/a> objects that are immediate children of the specified comment.<\/p>\n<p>The following code example shows how to iterate through a comment&rsquo;s replies and resolved them:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-comments-ProcessComments-CommentResolvedandReplies.java\"><\/script>\n\n\n      "},{"title":"Java: Track Changes in a Document in Java","link":"https:\/\/docs.aspose.com\/words\/java\/track-changes-in-a-document\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/track-changes-in-a-document\/","description":"\n        \n        \n        <p>The functionality of track changes, also known as reviewing, allows you to track changes to content and formatting made by you or other users. This track changes feature with Aspose.Words supports track changes in Microsoft Word. With this functionality, you can access individual revisions in your document and apply different properties to them.<\/p>\n<p>When you enable the track changes feature, all inserted, deleted, and modified elements of the document will be visually highlighted with information about by whom, when, and what was changed. Objects that carry information about what was changed are called \u201ctracking changes\u201d. For example, assume that you want to review a document and make important changes \u2013 this may mean that you need to make revisions. Also, you may need to insert comments to discuss some of the changes. That is where tracking changes in documents come in.<\/p>\n<p>This article explains how to manage and track changes created by many reviewers on the same document, as well as the properties for tracking changes.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the comment feature in Aspose.Words, as well as in Microsoft Word, can be associated with tracking changes. However, remember that comments are completely independent of tracking changes.\n<\/div>\n\n<h2 id=\"what-is-a-revision\">What Is a Revision<\/h2>\n<p>Before diving into revisions, let\u2019s explain the meaning of revisions. A <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/revision\/\">revision<\/a> is a change that occurs in one node of a document while a revision group, represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/revisiongroup\/\">RevisionGroup<\/a> class, is a group of sequential revisions that occur in many nodes of a document. Revision is a tool for tracking changes.<\/p>\n<p>Revisions are used in the tracking changes feature and within the compare documents feature, where revisions appear as a result of the comparison. So, revisions within the tracking changes feature shows by whom and what was changed.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that Microsoft Word does not allow you to view individual revisions, it only allows you to view sequential revisions as a single entity. But Aspose.Words solves this limitation with the <strong>RevisionGroup<\/strong> class.\n<\/div>\n\n<p>Aspose.Words supports different revision types, as well as in Microsoft Word, such as Insertion, Deletion, FormatChange, StyleDefinitionChange, and Moving. All revision types are represented with the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/revisiontype\/\">RevisionType<\/a> enumeration.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that revisions have a result similar to Microsoft Word but Aspose.Words does not detect formatting during tracking changes.\n<\/div>\n\n<h2 id=\"start-and-stop-tracking-changes\">Start and Stop Tracking Changes<\/h2>\n<p>Editing a document usually does not count as a revision until you begin tracking it. Aspose.Words allows you to automatically track all changes in your document with simple steps. You can easily start the process of tracking changes by using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#startTrackRevisions-java.lang.String\">StartTrackRevisions<\/a> method. If you need to stop the process of tracking changes so that any future edits are not considered revisions, you will need to use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#stopTrackRevisions\">StopTrackRevisions<\/a> method.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the <code>StartTrackingRevisions<\/code> method does not change the status of the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getTrackRevisions\">TrackRevisions<\/a> property and does not use its value for the aim of revision tracking. In addition, if a node was moved from one location to another inside the tracked document, then move revisions will be created, including move-from and move-to range.\n<\/div>\n\n<p>At the end of the tracking changes process in your document, you will have the ability to even accept all revisions or reject them to revert the document to its original form. This can be achieved by either using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#acceptAllRevisions\">AcceptAllRevisions<\/a> or <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/revisioncollection\/#rejectAll\">RejectAll<\/a> method. In addition, you can accept or reject each revision separately by using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/revision\/#accept\">Accept<\/a> or <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/revision\/#reject\">Reject<\/a> method.<\/p>\n<p>All changes will be tracked for one iteration from the moment you start the process to the moment you stop it. The connection between different iterations is represented as the following scenario: you complete the tracking process, then make some changes, and start tracking changes again. With this scenario, all changes that you did not accept or reject will be displayed again.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that the <code>AcceptAllRevisions<\/code> method is similar to the \u201cAccept All Changes\u201d in Microsoft Word.\n<\/div>\n\n<p>The following code example shows how to work with tracking changes:\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-TrackChanges-WorkWithTrackChanges.java\"><\/script>\n<\/p>\n<p>The following code example shows how revisions are generated when a node is moved within a tracked document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-TrackChanges-GenerateRevisionsWhenMovingNode.java\"><\/script>\n\n<h2 id=\"manage-and-store-changes-as-revisions\">Manage and Store Changes as Revisions<\/h2>\n<p>With the previous tracking changes feature, you can understand which changes were made in your document and who made those changes. While with the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getTrackRevisions\">TrackRevisions<\/a> feature, you force any changes within your document to be stored as revisions.<\/p>\n<p>Aspose.Words allows you to check if a document has a revision or not by using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#hasRevisions\">HasRevision<\/a> property. If you do not need to automatically track the changes in your document through the StartTrackRevisions and StopTrackRevisions methods, then you can use the <code>TrackRevisions<\/code> property to check if the changes are tracked while editing a document in Microsoft Word and stored as revisions.<\/p>\n<p>The <code>TrackRevisions<\/code> feature makes revisions instead of real DOM changes. But the revisions themselves are separate. For example, If you delete any paragraph, Aspose.Words make it as a revision, marking it as deletion, instead of deleting it.<\/p>\n<p>In addition, Aspose.Words allows you to check if an object was inserted, deleted, or changed formatting using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/inline\/#isDeleteRevision\">IsDeleteRevision<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/inline\/#isFormatRevision\">IsFormatRevision<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/inline\/#isInsertRevision\">IsInsertRevision<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/inline\/#isMoveFromRevision\">IsMoveFromRevision<\/a>, and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/inline\/#isMoveToRevision\">IsMoveToRevision<\/a> properties.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that there is no connection between the revisions themselves and the <code>TrackRevisions<\/code> property. In addition, you can accept\/reject revisions regardless of the tracking changes feature.\n<\/div>\n\n<p>The following code example shows how to apply different properties with revisions:\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-TrackChanges-ApplyDifferentPropertiesWithRevisions.java\"><\/script>\n<\/p>\n\n      "},{"title":"Java: Working with Shapes in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-shapes\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-shapes\/","description":"\n        \n        \n        <p>This topic discusses how to work programmatically with shapes using Aspose.Words.<\/p>\n<p>The shapes in Aspose.Words represent\u00a0an object in the drawing layer, such as an AutoShape, textbox, freeform, OLE object, ActiveX control, or picture.\u00a0A Word document can contain one or more different shapes. Shapes of the document are represented by the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/\">Shape<\/a>\u00a0class.<\/p>\n<h2 id=\"insert-shape-using-document-builder\">Insert Shape Using Document Builder<\/h2>\n<p>You can insert inline shape with specified type and size and free-floating shape with the specified position, size and text wrap type into a document using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertShape-int-double-double\">InsertShape<\/a> method. The <strong>InsertShape<\/strong> method allows inserting DML shape into the document model. The document must be saved in the format, which supports DML shapes, otherwise, such nodes will be converted to VML shape, while document saving.<\/p>\n<p>The following code example shows how to insert these types of shapes into the document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-InsertShapeUsingDocumentBuilder.java\"><\/script>\n\n<h2 id=\"set-aspect-ratio-locked\">Set Aspect Ratio Locked<\/h2>\n<p>Using Aspose.Words, you can specify whether the shape\u2019s aspect ratio is locked through the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shapebase\/#getAspectRatioLocked\">AspectRatioLocked<\/a> property.<\/p>\n<p>The following code example shows how to work with the <strong>AspectRatioLocked<\/strong> property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-SetAspectRatioLocked.java\"><\/script>\n\n<h2 id=\"set-shape-layout-in-cell\">Set Shape Layout In Cell<\/h2>\n<p>You can also specify whether the shape is displayed inside a table or outside of it using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shapebase\/#isLayoutInCell\">IsLayoutInCell<\/a> property.<\/p>\n<p>The following code example shows how to work with the <strong>IsLayoutInCell<\/strong> property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-SetShapeLayoutInCell.java\"><\/script>\n\n<h2 id=\"add-corners-snipped\">Add Corners Snipped<\/h2>\n<p>You can create a snip corner rectangle using Aspose.Words. The shape types are <em>SingleCornerSnipped, TopCornersSnipped, DiagonalCornersSnipped,\u00a0 TopCornersOneRoundedOneSnipped,\u00a0 SingleCornerRounded,\u00a0 TopCornersRounded,<\/em>\u00a0 and <em>DiagonalCornersRounded.<\/em><\/p>\n<p>The DML shape is created using <strong>InsertShape<\/strong> method with these shape types. These types\u00a0cannot be used to create VML shapes. Attempt to create shape by using the public constructor of the &ldquo;Shape&rdquo; class raises the &ldquo;NotSupportedException&rdquo; exception.<\/p>\n<p>The following code example shows how to insert these type of shapes into the document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-AddCornersSnipped.java\"><\/script>\n\n<h2 id=\"get-actual-shape-bounds-points\">Get Actual Shape Bounds Points<\/h2>\n<p>Using Aspose.Words API, you can get the location and size of the shape containing block in points, relative to the anchor of the topmost shape. To do this, use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shapebase\/#getBoundsInPoints\">BoundsInPoints<\/a> property.<\/p>\n<p>The following code example shows how to work with the <strong>BoundsInPoints<\/strong> property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-GetActualShapeBoundsPoints.java\"><\/script>\n\n<h2 id=\"specify-vertical-anchor\">Specify Vertical Anchor<\/h2>\n<p>You can specify the text vertical alignment within a shape using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/textbox\/#getVerticalAnchor\">VerticalAnchor<\/a> property.<\/p>\n<p>The following code example shows how to work with the <strong>VerticalAnchor<\/strong> property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-SpecifyVerticalAnchor.java\"><\/script>\n\n<h2 id=\"detect-smartart-shape\">Detect SmartArt Shape<\/h2>\n<p>Aspose.Words also allows to detect if the Shape has a <code>SmartArt<\/code> object. To do this, use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#hasSmartArt\">HasSmartArt<\/a> property.<\/p>\n<p>The following code example shows how to work with the <strong>HasSmartArt<\/strong> property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-DetectSmartArtShape.java\"><\/script>\n\n<h2 id=\"horizontal-rule-format\">Horizontal Rule Format<\/h2>\n<p>You can insert horizontal rule shape into a document using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertHorizontalRule\">InsertHorizontalRule<\/a> method.<\/p>\n<p>Aspose.Words API provides\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#getHorizontalRuleFormat\">HorizontalRuleFormat<\/a> property to access the properties of the horizontal rule shape. The\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/horizontalruleformat\/\">HorizontalRuleFormat<\/a> class exposes basic properties like Height, Color, NoShade etc. for the formatting of a horizontal rule.<\/p>\n<p>The following code example shows how to set\u00a0<strong>HorizontalRuleFormat<\/strong>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-ShapeHorizontalRuleFormat.java\"><\/script>\n\n\n      "},{"title":"Java: How to Add Group Shape into a Word Document","link":"https:\/\/docs.aspose.com\/words\/java\/how-to-add-group-shape-into-a-word-document\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/how-to-add-group-shape-into-a-word-document\/","description":"\n        \n        \n        <p>Sometimes you need to add a group shape into a Word document. Such a group shape consists of multiple shapes.<\/p>\n<p>In Microsoft Word, you can quickly add a group shape using the Group command\/button. Individual shapes in a group can be moved separately.<\/p>\n<p>In Aspose.Words it is very easy to add a group shape using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/groupshape\/\">GroupShape<\/a> class. <strong>Shape<\/strong> is created separately using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/\">Shape<\/a> class and then added in <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/groupshape\/\">GroupShape<\/a> object using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/groupshape\/#appendChild-com.aspose.words.Node\">AppendChild<\/a> method.<\/p>\n<p>Below are some of the <code>Shape<\/code> types supported in Aspose.Words. For complete list, please visit <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shapetype\/\">ShapeType<\/a>:<\/p>\n<ul>\n<li>Rectangle<\/li>\n<li>RoundRectangle<\/li>\n<li>RoundRectangle<\/li>\n<li>Ellipse<\/li>\n<li>Diamond<\/li>\n<li>Triangle<\/li>\n<li>RightTriangle<\/li>\n<li>Parallelogram<\/li>\n<li>Trapezoid<\/li>\n<li>Hexagon<\/li>\n<li>Octagon<\/li>\n<\/ul>\n<p><strong>Example<\/strong><\/p>\n<p><em>Add a group shape into a Word document.<\/em><\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">package<\/span> <span class=\"n\">AddGroupShape<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">import<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.*;<\/span>\n<span class=\"n\">import<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.*;<\/span>\n<span class=\"n\">import<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Fields<\/span><span class=\"p\">.*;<\/span>\n<span class=\"k\">public<\/span> <span class=\"k\">class<\/span> <span class=\"nc\">Program<\/span>\n<span class=\"p\">{<\/span>\n\t<span class=\"k\">public<\/span> <span class=\"k\">static<\/span> <span class=\"k\">void<\/span> <span class=\"n\">main<\/span><span class=\"p\">(<\/span><span class=\"n\">String<\/span><span class=\"p\">[]<\/span> <span class=\"n\">args<\/span><span class=\"p\">)<\/span>\n\t<span class=\"p\">{<\/span>\n\t\t<span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Document<\/span> <span class=\"n\">doc<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Document<\/span><span class=\"p\">();<\/span>\n\t        <span class=\"n\">doc<\/span><span class=\"p\">.<\/span><span class=\"n\">EnsureMinimum<\/span><span class=\"p\">();<\/span>\n\t\t<span class=\"n\">GroupShape<\/span> <span class=\"n\">gs<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">GroupShape<\/span><span class=\"p\">(<\/span><span class=\"n\">doc<\/span><span class=\"p\">);<\/span>\n\t\t<span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.<\/span><span class=\"n\">Shape<\/span> <span class=\"n\">shape<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.<\/span><span class=\"n\">Shape<\/span><span class=\"p\">(<\/span><span class=\"n\">doc<\/span><span class=\"p\">,<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.<\/span><span class=\"n\">ShapeType<\/span><span class=\"p\">.<\/span><span class=\"n\">AccentBorderCallout1<\/span><span class=\"p\">);<\/span>\n\t\t<span class=\"n\">shape<\/span><span class=\"p\">.<\/span><span class=\"n\">Width<\/span> <span class=\"p\">=<\/span> <span class=\"m\">100<\/span><span class=\"p\">;<\/span>\n\t\t<span class=\"n\">shape<\/span><span class=\"p\">.<\/span><span class=\"n\">Height<\/span> <span class=\"p\">=<\/span> <span class=\"m\">100<\/span><span class=\"p\">;<\/span>\n\t\t<span class=\"n\">gs<\/span><span class=\"p\">.<\/span><span class=\"n\">AppendChild<\/span><span class=\"p\">(<\/span><span class=\"n\">shape<\/span><span class=\"p\">);<\/span>\n\t\t<span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.<\/span><span class=\"n\">Shape<\/span> <span class=\"n\">shape1<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.<\/span><span class=\"n\">Shape<\/span><span class=\"p\">(<\/span><span class=\"n\">doc<\/span><span class=\"p\">,<\/span> <span class=\"n\">Aspose<\/span><span class=\"p\">.<\/span><span class=\"n\">Words<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.<\/span><span class=\"n\">ShapeType<\/span><span class=\"p\">.<\/span><span class=\"n\">ActionButtonBeginning<\/span><span class=\"p\">);<\/span>\n\t\t<span class=\"n\">shape1<\/span><span class=\"p\">.<\/span><span class=\"n\">Left<\/span> <span class=\"p\">=<\/span> <span class=\"m\">100<\/span><span class=\"p\">;<\/span>\n\t\t<span class=\"n\">shape1<\/span><span class=\"p\">.<\/span><span class=\"n\">Width<\/span> <span class=\"p\">=<\/span> <span class=\"m\">100<\/span><span class=\"p\">;<\/span>\n\t\t<span class=\"n\">shape1<\/span><span class=\"p\">.<\/span><span class=\"n\">Height<\/span> <span class=\"p\">=<\/span> <span class=\"m\">200<\/span><span class=\"p\">;<\/span>\n\t\t<span class=\"n\">gs<\/span><span class=\"p\">.<\/span><span class=\"n\">AppendChild<\/span><span class=\"p\">(<\/span><span class=\"n\">shape1<\/span><span class=\"p\">);<\/span>\n\t        <span class=\"n\">gs<\/span><span class=\"p\">.<\/span><span class=\"n\">Width<\/span> <span class=\"p\">=<\/span> <span class=\"m\">200<\/span><span class=\"p\">;<\/span>\n\t\t<span class=\"n\">gs<\/span><span class=\"p\">.<\/span><span class=\"n\">Height<\/span> <span class=\"p\">=<\/span> <span class=\"m\">200<\/span><span class=\"p\">;<\/span>\n\t\t<span class=\"n\">gs<\/span><span class=\"p\">.<\/span><span class=\"n\">CoordSize<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">System<\/span><span class=\"p\">.<\/span><span class=\"n\">Drawing<\/span><span class=\"p\">.<\/span><span class=\"n\">Size<\/span><span class=\"p\">(<\/span><span class=\"m\">200<\/span><span class=\"p\">,<\/span> <span class=\"m\">200<\/span><span class=\"p\">);<\/span>\n\t\t<span class=\"n\">DocumentBuilder<\/span> <span class=\"n\">builder<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">DocumentBuilder<\/span><span class=\"p\">(<\/span><span class=\"n\">doc<\/span><span class=\"p\">);<\/span>\n\t\t<span class=\"n\">builder<\/span><span class=\"p\">.<\/span><span class=\"n\">InsertNode<\/span><span class=\"p\">(<\/span><span class=\"n\">gs<\/span><span class=\"p\">);<\/span>\n\t\t<span class=\"n\">doc<\/span><span class=\"p\">.<\/span><span class=\"n\">Save<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;c:\\\\TestFile.docx&#34;<\/span><span class=\"p\">);<\/span>\n\t<span class=\"p\">}<\/span>\n<span class=\"p\">}<\/span>\n<\/code><\/pre><\/div>\n\n      "},{"title":"Java: Working with Images in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-images\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-images\/","description":"\n        \n        \n        <p>Aspose.Words allows users to work with images in a very flexible way. In this article, you can explore only some of the possibilities of working with images.<\/p>\n<h2 id=\"how-to-extract-images-from-a-document\">How to Extract Images from a Document<\/h2>\n<p>All images are stored inside <strong>Shape<\/strong> nodes in a Document.\u00a0To extract all images or images having a specific type from the document, follow these steps:<\/p>\n<ul>\n<li>Use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#getChildNodes\">getChildNodes<\/a> method to select all Shape nodes.<\/li>\n<li>Iterate through resulting node collections.<\/li>\n<li>Check the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#hasImage\">hasImage<\/a> boolean property.<\/li>\n<li>Extract image data using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#getImageData\">ImageData<\/a> property.<\/li>\n<li>Save image data to a file.<\/li>\n<\/ul>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-images-ExtractImagesToFiles-ExtractImagesToFiles.java\"><\/script>\n\n<h2 id=\"how-to-insert-barcode-on-each-documen-page\">How to Insert Barcode on each Document Page<\/h2>\n<p>This example lets you add the same or different barcodes on all or specific pages of a Word document. There is no direct way to add barcodes on all pages of a document but you can use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#moveToSection-int\">moveToSection<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#moveToHeaderFooter-int\">moveToHeaderFooter<\/a> and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/DocumentBuilder#insertImage(byte%5B%5D)\">insertImage<\/a> methods to move to any section or headers\/footers and insert the barcode images as you can see in the following code.\u00a0<\/p>\n<p>The following code example shows how to insert a barcode image on each page of a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-images-InsertBarcodeImage-InsertBarcodeImage.java\"><\/script>\n\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-images-InsertBarcodeImage-InsertBarcodeIntoFooter.java\"><\/script>\n\n<h2 id=\"lock-aspect-ratio-of-image\">Lock Aspect Ratio of Image<\/h2>\n<p>The aspect ratio of a geometric shape is the ratio of its sizes in different dimensions. You can lock the aspect ratio of an image using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#getAspectRatioLocked\">AspectRatioLocked<\/a>. The default value of the shape&rsquo;s aspect ratio depends on the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shapetype\/\">ShapeType<\/a>. It is true for <code>ShapeType.Image<\/code> and false for other shape types.<\/p>\n<p>The following code example shows how to work with aspect ratio:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderSetImageAspectRatioLocked-DocumentBuilderSetImageAspectRatioLocked.java\"><\/script>\n\n<h2 id=\"how-to-get-actual-bounds-of-shape-in-points\">How to Get Actual Bounds of Shape in Points<\/h2>\n<p>If you want the actual bounding box of the shape as rendered on the page, you can achieve this by using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/noderendererbase\/#getBoundsInPoints\">BoundsInPoints<\/a> property.<\/p>\n<p>The following code example shows how to use this property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-GetActualShapeBoundsPoints.java\"><\/script>\n\n<h2 id=\"crop-images\">Crop Images<\/h2>\n<p>The cropping of an image\u00a0usually refers to the removal of the unwanted\u00a0outer parts of an image to help improve the framing. It is also used for the\u00a0removal of some of the\u00a0portions of an image to increase the focus on a particular area.<\/p>\n<p>The following code example shows how to achieve this using Aspose.Words API:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-images-CropImages-CropImageCall.java\"><\/script>\n\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-images-CropImages-CropImage.java\"><\/script>\n\n<h2 id=\"saving-images-as-wmf\">Saving Images as WMF<\/h2>\n<p>Aspose.Words provides functionality to save all the available images in a document to\u00a0<a href=\"https:\/\/docs.fileformat.com\/image\/wmf\/\">WMF\u00a0<\/a>format while converting DOCX to RTF.<\/p>\n<p>The following code example shows how to save images as WMF with RTF save options:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-WorkingWithRtfSaveOptions-SavingImagesAsWmf.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I extract all images from a Word document using Aspose.Words for Java?<br>\n<strong>A:<\/strong> Load the document, retrieve all <code>Shape<\/code> nodes with <code>document.getChildNodes(NodeType.SHAPE, true)<\/code>, iterate the collection, check <code>shape.hasImage()<\/code>, then obtain the image bytes via <code>shape.getImageData().getImageBytes()<\/code> and write them to files.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What is the recommended way to add a barcode image to every page of a document?<br>\n<strong>A:<\/strong> Use <code>DocumentBuilder<\/code> to navigate to each section\u2019s header or footer with <code>moveToHeaderFooter(HeaderFooterType.HEADER_PRIMARY)<\/code> (or footer), then call <code>insertImage(byte[])<\/code> with the barcode image data. Repeat for all sections to place the barcode on each page.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I lock the aspect ratio of an image after inserting it?<br>\n<strong>A:<\/strong> After inserting the image, the returned <code>Shape<\/code> object represents the picture. Call <code>shape.setAspectRatioLocked(true)<\/code> to keep the original width\u2011to\u2011height proportion when the shape is resized.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I crop an image that is already inside a Word document?<br>\n<strong>A:<\/strong> Yes. Obtain the <code>Shape<\/code> that contains the image and use the cropping properties: <code>shape.getImageData().setCropTop(value)<\/code>, <code>setCropBottom(value)<\/code>, <code>setCropLeft(value)<\/code>, and <code>setCropRight(value)<\/code>. The values are specified as percentages (0.0 to 1.0).<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I save all images in a document as WMF when converting to RTF?<br>\n<strong>A:<\/strong> Create an <code>RtfSaveOptions<\/code> instance, set <code>options.setImageSavingCallback(new ImageSavingCallback() { \u2026 })<\/code> and inside the callback save each image with <code>ImageSaveOptions.setImageFormat(ImageFormat.WMF)<\/code>. Then call <code>document.save(&quot;output.rtf&quot;, options)<\/code> to produce an RTF where all images are stored as WMF.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Charts in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-charts\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-charts\/","description":"\n        \n        \n        <p>The new <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertChart-int-double-double\">insertChart<\/a> method was added into the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> class. So, let&rsquo;s see how to insert a simple column chart into the document using <strong>insertChart<\/strong> method.<\/p>\n<h2 id=\"how-to-insert-a-chart-from-scratch-using-asposewords\">How to Insert a Chart from Scratch using Aspose.Words<\/h2>\n<p>In this section we will learn how to insert a chart into a document.<\/p>\n<h3 id=\"insert-column-chart\">Insert Column Chart<\/h3>\n<p>The following code example shows how to insert column chart:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-OOXMLCharts-insertColumnChart1.java\"><\/script>\n\n<p>The code produces the following result:<\/p>\n<p><img src=\"working-with-charts-7.png\" alt=\"column-chart-aspose-words-java-1\"><\/p>\n<p>There are four different overloads for the series Add method, which were exposed to cover all possible variants of data sources for all chart types:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-OOXMLCharts-insertColumnChart2.java\"><\/script>\n\n<p>The code produces the following result:<\/p>\n<p><img src=\"working-with-charts-8.png\" alt=\"column-chart-aspose-words-java-2\"><\/p>\n<h3 id=\"insert-scatter-chart\">Insert Scatter Chart<\/h3>\n<p>The following code example shows how to insert a scatter chart:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-OOXMLCharts-insertScatterChart.java\"><\/script>\n\n<p>The code produces the following result:<\/p>\n<p><img src=\"working-with-charts-9.png\" alt=\"scutter-chart-aspose-words-java\"><\/p>\n<h3 id=\"insert-area-chart\">Insert Area Chart<\/h3>\n<p>The following code example shows how to insert an area chart:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-OOXMLCharts-insertAreaChart.java\"><\/script>\n\n<p>The code produces the following result:<\/p>\n<p><img src=\"working-with-charts-10.png\" alt=\"area-chart-aspose-words-java\"><\/p>\n<h3 id=\"insert-bubble-chart\">Insert Bubble Chart<\/h3>\n<p>The following code example shows how to insert a bubble chart:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-OOXMLCharts-insertBubbleChart.java\"><\/script>\n\n<p>The code produces the following result:<\/p>\n<p><img src=\"working-with-charts-11.png\" alt=\"bubble-chart-aspose-words-java\"><\/p>\n<h2 id=\"working-with-charts-through-shapechart-object\">Working with Charts through <code>Shape.Chart<\/code> Object<\/h2>\n<p>Once the chart was inserted and filled with data, you are able to change its appearance. <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#getChart\">Shape.Chart<\/a> property contains all chart related options available through the public API.<\/p>\n<p>For example, let&rsquo;s change Chart title or legend behavior:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-ChartAppearance-changeChartAppearanceUsingShapeChartObject.java\"><\/script>\n\n<p>The code generates the followings results:<\/p>\n<p><img src=\"working-with-charts-1.png\" alt=\"line-chart-aspose-words-java-1\"><\/p>\n<h2 id=\"how-to-work-with-chartseriescollection-of-chart\">How to Work with ChartSeriesCollection of Chart<\/h2>\n<p>Let\u2019s look into <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartseries\/\">ChartSeries<\/a> collection. All chart series are available through the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chart\/#getSeries\">chart.getSeries()<\/a> collection, which is <strong>Iterable<\/strong>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkWithChartSeriesCollectionOfChart-WorkWithChartSeriesCollectionOfChart.java\"><\/script>\n\n<p>You can remove series one by one or clear all of them as well as add a new one if needed. The newly inserted chart has some default series added to this collection. To remove them you need to call the <strong>chart.getSeries().clear()<\/strong> method.<\/p>\n<h2 id=\"working-with-single-chartseries-class\">Working with Single ChartSeries Class<\/h2>\n<p>Here is how to work with a particular series.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-ChartAppearance-workingWithSingleChartSeries.java\"><\/script>\n\n<p>Please see the result below:<\/p>\n<p><img src=\"working-with-charts-2.png\" alt=\"line-chart-aspose-words-java-2\"><\/p>\n<p>All single <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartseries\/\">ChartSeries<\/a> have default <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartdatapoint\/\">ChartDataPoint<\/a> options, please try using the following code to change them:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-ChartAppearance-changeDefaultChartDataPointOptions.java\"><\/script>\n\n<p><img src=\"working-with-charts-3.png\" alt=\"line-chart-aspose-words-java3\"><\/p>\n<h2 id=\"how-to-work-with-single-chartdatapoint-of-a-chartseries\">How to Work with Single ChartDataPoint of a <code>ChartSeries<\/code><\/h2>\n<p>Using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartdatapoint\/\">ChartDataPoint<\/a> you are able to customize the formatting of a single data point of the chart series:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkWithSingleChartDataPointOfAChartSeries-WorkWithSingleChartDataPointOfAChartSeries.java\"><\/script>\n\n<p>Please see the result below:<\/p>\n<p><img src=\"working-with-charts-4.png\" alt=\"line-chart-aspose-words-java-4\"><\/p>\n<h2 id=\"how-to-work-with-chartdatalabel-of-a-single-chartseries\">How to Work with ChartDataLabel of a Single ChartSeries<\/h2>\n<p>Using <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartdatalabel\/\">ChartDataLabel<\/a> you are able to specify the formatting of a single data label of the chart series, like show\/hide LegendKey, CategoryName, SeriesName, Value etc:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkWithChartDataLabelOfASingleChartSeries-WorkWithChartDataLabelOfASingleChartSeries.java\"><\/script>\n\n<p>Please see the result below:<\/p>\n<p><img src=\"working-with-charts-5.png\" alt=\"bar-chart-aspose-words-java\"><\/p>\n<h2 id=\"how-to-define-default-options-for-chartdatalabels-of-chartseries\">How to Define Default Options for ChartDataLabels of ChartSeries<\/h2>\n<p>The\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartdatalabelcollection\/\">ChartDataLabelCollection<\/a> class defines properties which can be used to set default options for <strong>ChartDataLabels<\/strong> for Chart <strong>Series<\/strong>. These properties include setShowCategoryName, setShowBubbleSize, setShowPercentage, setShowSeriesName, setShowValue etc:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-DefaultOptionsForDataLabels-DefaultOptionsForDataLabels.java\"><\/script>\n\n<p>Please see the result below:<\/p>\n<p><img src=\"working-with-charts-6.png\" alt=\"pie-chart-aspose-words-java\"><\/p>\n<h2 id=\"how-to-format-number-of-chart-data-label\">How to Format Number of Chart Data Label<\/h2>\n<p>Using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartdatalabel\/#getNumberFormat\">NumberFormat<\/a> property, you can specify the number formatting of a single data label of the chart.<\/p>\n<p>The following code example shows how to format a number of the data label:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-ChartNumberFormat-ChartNumberFormat.java\"><\/script>\n\n<h2 id=\"how-toset-chart-axis-properties\">How to\u00a0Set Chart Axis Properties<\/h2>\n<p>If you want to work with chart axis, scaling, and display units for the value axis, please use <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartaxis\/\">ChartAxis<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/axisdisplayunit\/\">AxisDisplayUnit<\/a>, and <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/axisscaling\/\">AxisScaling<\/a> classes.<\/p>\n<p>The following code example shows how to define X and Y-axis properties:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkingWithChartAxis-DefineXYAxisProperties.java\"><\/script>\n\n<h3 id=\"how-to-set-datetime-value-of-axis\">How to Set DateTime Value of Axis<\/h3>\n<p>The following code example shows how to set date\/time values to axis properties:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkingWithChartAxis-SetDateTimeValuesToAxis.java\"><\/script>\n\n<h3 id=\"how-to-format-number-value-of-axis\">How to Format Number Value of Axis<\/h3>\n<p>The following code example shows how to\u00a0change the format of numbers on the value axis:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkingWithChartAxis-SetNumberFormatForAxis.java\"><\/script>\n\n<h3 id=\"how-to-set-bounds-of-axis\">How to Set Bounds of Axis<\/h3>\n<p>The <code>AxisBound<\/code> class represents a minimum or maximum bound of axis values. Bound can be specified as a numeric, date-time or a special &ldquo;auto&rdquo; value.<\/p>\n<p>The following code example shows how\u00a0to set the bounds of an axis:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkingWithChartAxis-SetboundsOfAxis.java\"><\/script>\n\n<h3 id=\"how-to-set-interval-unit-between-labels\">How to Set Interval Unit Between Labels<\/h3>\n<p>The following code example shows how\u00a0to set\u00a0the interval unit between labels on an axis:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkingWithChartAxis-SetIntervalUnitBetweenLabelsOnAxis.java\"><\/script>\n\n<h3 id=\"how-to-hide-chart-axis\">How to Hide Chart Axis<\/h3>\n<p>If you want to show or hide the chart axis, you can simply achieve this by setting the value of <code>ChartAxis.Hidden<\/code> property.<\/p>\n<p>The following code example shows how to hide the Y-axis of the chart:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkingWithChartAxis-HideChartAxis.java\"><\/script>\n\n<h3 id=\"how-to-align-chart-label\">How to Align Chart Label<\/h3>\n<p>If you want to set a text alignment for multi-line labels, you can simply achieve this by setting the value of <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/chartaxis\/#setTickLabelAlignment-int\">setTickLabelAlignment()<\/a> property.<\/p>\n<p>The following code example shows how to tick label alignment:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-charts-WorkingWithChartAxis-TickMultiLineLabelAlignment.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nMicrosoft Word aligns Chart Label to the center by default.\n<\/div>\n\n<h2 id=\"how-to-set-fill-and-stroke-formatting\">How to Set Fill and Stroke Formatting<\/h2>\n<p>Fill and stroke formatting can be set for chart series, data points, and markers. To do this, you need to use the properties of the <code>ChartFormat<\/code> type in the ChartSeries, ChartDataPoint, and ChartMarker classes, as well as aliases for some properties, such as ForeColor, BackColor, Visible, and Transparency in the <code>Stroke<\/code> class.<\/p>\n<p>The following code example shows how to set series color:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">Document<\/span> <span class=\"n\">doc<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Document<\/span><span class=\"p\">();<\/span>\n<span class=\"n\">DocumentBuilder<\/span> <span class=\"n\">builder<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">DocumentBuilder<\/span><span class=\"p\">(<\/span><span class=\"n\">doc<\/span><span class=\"p\">);<\/span>\n\n<span class=\"n\">Shape<\/span> <span class=\"n\">shape<\/span> <span class=\"p\">=<\/span> <span class=\"n\">builder<\/span><span class=\"p\">.<\/span><span class=\"n\">InsertChart<\/span><span class=\"p\">(<\/span><span class=\"n\">ChartType<\/span><span class=\"p\">.<\/span><span class=\"n\">Column<\/span><span class=\"p\">,<\/span> <span class=\"m\">432<\/span><span class=\"p\">,<\/span> <span class=\"m\">252<\/span><span class=\"p\">);<\/span>\n\n<span class=\"n\">Chart<\/span> <span class=\"n\">chart<\/span> <span class=\"p\">=<\/span> <span class=\"n\">shape<\/span><span class=\"p\">.<\/span><span class=\"n\">Chart<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">ChartSeriesCollection<\/span> <span class=\"n\">seriesColl<\/span> <span class=\"p\">=<\/span> <span class=\"n\">chart<\/span><span class=\"p\">.<\/span><span class=\"n\">Series<\/span><span class=\"p\">;<\/span>\n\n<span class=\"c1\">\/\/ Delete default generated series.\n<\/span><span class=\"c1\"><\/span><span class=\"n\">seriesColl<\/span><span class=\"p\">.<\/span><span class=\"n\">Clear<\/span><span class=\"p\">();<\/span>\n\n<span class=\"c1\">\/\/ Create category names array.\n<\/span><span class=\"c1\"><\/span><span class=\"kt\">string<\/span><span class=\"p\">[]<\/span> <span class=\"n\">categories<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">string<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"s\">&#34;AW Category 1&#34;<\/span><span class=\"p\">,<\/span> <span class=\"s\">&#34;AW Category 2&#34;<\/span> <span class=\"p\">};<\/span>\n\n<span class=\"c1\">\/\/ Adding new series. Value and category arrays must be the same size.\n<\/span><span class=\"c1\"><\/span><span class=\"n\">ChartSeries<\/span> <span class=\"n\">series1<\/span> <span class=\"p\">=<\/span> <span class=\"n\">seriesColl<\/span><span class=\"p\">.<\/span><span class=\"n\">Add<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;AW Series 1&#34;<\/span><span class=\"p\">,<\/span> <span class=\"n\">categories<\/span><span class=\"p\">,<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">double<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"m\">1<\/span><span class=\"p\">,<\/span> <span class=\"m\">2<\/span> <span class=\"p\">});<\/span>\n<span class=\"n\">ChartSeries<\/span> <span class=\"n\">series2<\/span> <span class=\"p\">=<\/span> <span class=\"n\">seriesColl<\/span><span class=\"p\">.<\/span><span class=\"n\">Add<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;AW Series 2&#34;<\/span><span class=\"p\">,<\/span> <span class=\"n\">categories<\/span><span class=\"p\">,<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">double<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"m\">3<\/span><span class=\"p\">,<\/span> <span class=\"m\">4<\/span> <span class=\"p\">});<\/span>\n<span class=\"n\">ChartSeries<\/span> <span class=\"n\">series3<\/span> <span class=\"p\">=<\/span> <span class=\"n\">seriesColl<\/span><span class=\"p\">.<\/span><span class=\"n\">Add<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;AW Series 3&#34;<\/span><span class=\"p\">,<\/span> <span class=\"n\">categories<\/span><span class=\"p\">,<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">double<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"m\">5<\/span><span class=\"p\">,<\/span> <span class=\"m\">6<\/span> <span class=\"p\">});<\/span>\n\n<span class=\"c1\">\/\/ Set series color.\n<\/span><span class=\"c1\"><\/span><span class=\"n\">series1<\/span><span class=\"p\">.<\/span><span class=\"n\">Format<\/span><span class=\"p\">.<\/span><span class=\"n\">Fill<\/span><span class=\"p\">.<\/span><span class=\"n\">ForeColor<\/span> <span class=\"p\">=<\/span> <span class=\"n\">Color<\/span><span class=\"p\">.<\/span><span class=\"n\">Red<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">series2<\/span><span class=\"p\">.<\/span><span class=\"n\">Format<\/span><span class=\"p\">.<\/span><span class=\"n\">Fill<\/span><span class=\"p\">.<\/span><span class=\"n\">ForeColor<\/span> <span class=\"p\">=<\/span> <span class=\"n\">Color<\/span><span class=\"p\">.<\/span><span class=\"n\">Yellow<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">series3<\/span><span class=\"p\">.<\/span><span class=\"n\">Format<\/span><span class=\"p\">.<\/span><span class=\"n\">Fill<\/span><span class=\"p\">.<\/span><span class=\"n\">ForeColor<\/span> <span class=\"p\">=<\/span> <span class=\"n\">Color<\/span><span class=\"p\">.<\/span><span class=\"n\">Blue<\/span><span class=\"p\">;<\/span>\n\n<span class=\"n\">doc<\/span><span class=\"p\">.<\/span><span class=\"n\">Save<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;ColumnColor.docx&#34;<\/span><span class=\"p\">);<\/span>\n<\/code><\/pre><\/div>\n<p>The following code example shows how to set line color and weight:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">Document<\/span> <span class=\"n\">doc<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Document<\/span><span class=\"p\">();<\/span>\n<span class=\"n\">DocumentBuilder<\/span> <span class=\"n\">builder<\/span> <span class=\"p\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">DocumentBuilder<\/span><span class=\"p\">(<\/span><span class=\"n\">doc<\/span><span class=\"p\">);<\/span>\n\n<span class=\"n\">Shape<\/span> <span class=\"n\">shape<\/span> <span class=\"p\">=<\/span> <span class=\"n\">builder<\/span><span class=\"p\">.<\/span><span class=\"n\">InsertChart<\/span><span class=\"p\">(<\/span><span class=\"n\">ChartType<\/span><span class=\"p\">.<\/span><span class=\"n\">Line<\/span><span class=\"p\">,<\/span> <span class=\"m\">432<\/span><span class=\"p\">,<\/span> <span class=\"m\">252<\/span><span class=\"p\">);<\/span>\n\n<span class=\"n\">Chart<\/span> <span class=\"n\">chart<\/span> <span class=\"p\">=<\/span> <span class=\"n\">shape<\/span><span class=\"p\">.<\/span><span class=\"n\">Chart<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">ChartSeriesCollection<\/span> <span class=\"n\">seriesColl<\/span> <span class=\"p\">=<\/span> <span class=\"n\">chart<\/span><span class=\"p\">.<\/span><span class=\"n\">Series<\/span><span class=\"p\">;<\/span>\n\n<span class=\"c1\">\/\/ Delete default generated series.\n<\/span><span class=\"c1\"><\/span><span class=\"n\">seriesColl<\/span><span class=\"p\">.<\/span><span class=\"n\">Clear<\/span><span class=\"p\">();<\/span>\n\n<span class=\"c1\">\/\/ Adding new series.\n<\/span><span class=\"c1\"><\/span><span class=\"n\">ChartSeries<\/span> <span class=\"n\">series1<\/span> <span class=\"p\">=<\/span> <span class=\"n\">seriesColl<\/span><span class=\"p\">.<\/span><span class=\"n\">Add<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;AW Series 1&#34;<\/span><span class=\"p\">,<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">double<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"m\">0.7<\/span><span class=\"p\">,<\/span> <span class=\"m\">1.8<\/span><span class=\"p\">,<\/span> <span class=\"m\">2.6<\/span> <span class=\"p\">},<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">double<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"m\">2.7<\/span><span class=\"p\">,<\/span> <span class=\"m\">3.2<\/span><span class=\"p\">,<\/span> <span class=\"m\">0.8<\/span> <span class=\"p\">});<\/span>\n<span class=\"n\">ChartSeries<\/span> <span class=\"n\">series2<\/span> <span class=\"p\">=<\/span> <span class=\"n\">seriesColl<\/span><span class=\"p\">.<\/span><span class=\"n\">Add<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;AW Series 2&#34;<\/span><span class=\"p\">,<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">double<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"m\">0.5<\/span><span class=\"p\">,<\/span> <span class=\"m\">1.5<\/span><span class=\"p\">,<\/span> <span class=\"m\">2.5<\/span> <span class=\"p\">},<\/span> <span class=\"k\">new<\/span> <span class=\"kt\">double<\/span><span class=\"p\">[]<\/span> <span class=\"p\">{<\/span> <span class=\"m\">3<\/span><span class=\"p\">,<\/span> <span class=\"m\">1<\/span><span class=\"p\">,<\/span> <span class=\"m\">2<\/span> <span class=\"p\">});<\/span>\n\n<span class=\"c1\">\/\/ Set series color.\n<\/span><span class=\"c1\"><\/span><span class=\"n\">series1<\/span><span class=\"p\">.<\/span><span class=\"n\">Format<\/span><span class=\"p\">.<\/span><span class=\"n\">Stroke<\/span><span class=\"p\">.<\/span><span class=\"n\">ForeColor<\/span> <span class=\"p\">=<\/span> <span class=\"n\">Color<\/span><span class=\"p\">.<\/span><span class=\"n\">Red<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">series1<\/span><span class=\"p\">.<\/span><span class=\"n\">Format<\/span><span class=\"p\">.<\/span><span class=\"n\">Stroke<\/span><span class=\"p\">.<\/span><span class=\"n\">Weight<\/span> <span class=\"p\">=<\/span> <span class=\"m\">5<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">series2<\/span><span class=\"p\">.<\/span><span class=\"n\">Format<\/span><span class=\"p\">.<\/span><span class=\"n\">Stroke<\/span><span class=\"p\">.<\/span><span class=\"n\">ForeColor<\/span> <span class=\"p\">=<\/span> <span class=\"n\">Color<\/span><span class=\"p\">.<\/span><span class=\"n\">LightGreen<\/span><span class=\"p\">;<\/span>\n<span class=\"n\">series2<\/span><span class=\"p\">.<\/span><span class=\"n\">Format<\/span><span class=\"p\">.<\/span><span class=\"n\">Stroke<\/span><span class=\"p\">.<\/span><span class=\"n\">Weight<\/span> <span class=\"p\">=<\/span> <span class=\"m\">5<\/span><span class=\"p\">;<\/span>\n\n<span class=\"n\">doc<\/span><span class=\"p\">.<\/span><span class=\"n\">Save<\/span><span class=\"p\">(<\/span><span class=\"s\">&#34;LineColorAndWeight.docx&#34;<\/span><span class=\"p\">);<\/span>\n<\/code><\/pre><\/div>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I set date\/time values on a chart axis?<br>\n<strong>A:<\/strong> Use the <code>ChartAxis.setNumberFormat(String)<\/code> method with a date\u2011time format string (e.g., <code>&quot;mm\/dd\/yyyy&quot;<\/code>). First obtain the axis via <code>chart.getAxisX()<\/code> or <code>chart.getAxisY()<\/code>, then call <code>setNumberFormat<\/code>. You can also set the axis bounds with <code>AxisBound<\/code> objects that accept <code>Date<\/code> values.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I change the number format of axis labels?<br>\n<strong>A:<\/strong> Call <code>ChartAxis.setNumberFormat(String format)<\/code> on the desired axis. For example, <code>chart.getAxisY().setNumberFormat(&quot;#,##0.00&quot;)<\/code> will display values with two decimal places and thousand separators.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I hide or show a chart axis?<br>\n<strong>A:<\/strong> Set the <code>ChartAxis.setHidden(boolean)<\/code> property. <code>chart.getAxisY().setHidden(true)<\/code> hides the Y\u2011axis, while setting it to <code>false<\/code> makes it visible again.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I customize the fill color of a chart series or a single data point?<br>\n<strong>A:<\/strong> Access the <code>ChartFormat<\/code> of the series or data point. For a series: <code>series.getFormat().getFill().setForeColor(Color.getRed())<\/code>. For a data point: <code>dataPoint.getFormat().getFill().setForeColor(Color.getGreen())<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I align multi\u2011line axis labels?<br>\n<strong>A:<\/strong> Use <code>ChartAxis.setTickLabelAlignment(int alignment)<\/code>. Pass one of the alignment constants defined in <code>ChartAxis<\/code> (e.g., <code>ChartAxisAlignment.Center<\/code>, <code>ChartAxisAlignment.Left<\/code>). This aligns the tick labels for better readability when they span multiple lines.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with OfficeMath in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-officemath\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-officemath\/","description":"\n        \n        \n        <p>Now it is even more convenient to work with OfficeMath Type Objects. In Aspose.Words, the customer can easily Justify and can also manage whether an equation is displayed inline or in a separate line. More so, with the availability of\u00a0<strong>MathObjectType<\/strong>; useful controls can be implemented by use this matrix object.<\/p>\n<p>The following code examples shows how to make use of these properties:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-fields-UseOfficeMathProperties-UseOfficeMathProperties.java\"><\/script>\n\n\n      "},{"title":"Java: Working with SmartArt Cold Rendering in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-smartart-cold-rendering\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-smartart-cold-rendering\/","description":"\n        \n        \n        <p>SmartArt graphics are used to quickly and easily create a visual representation of information. You simply choose from a large number of layouts that best suits your situation. This ease of use makes SmartArt graphics quite popular for some purposes.<\/p>\n<p>Microsoft Word generates and saves the pre-rendered drawing along with the <code>SmartArt<\/code> object. In most cases, the pre-rendered drawing is rendered well by Aspose.Words and no additional actions are required. However, if the document is saved by other applications, the pre-rendered SmartArt drawing may be missing or incorrect. In this case, the <code>SmartArt<\/code> object itself should be laid-out and rendered using Aspose.Words. We call this process the <code>SmartArt<\/code> Cold Rendering.<\/p>\n<h2 id=\"using-smartart-cold-rendering\">Using SmartArt Cold Rendering<\/h2>\n<p>Aspose.Words allows you to use a pre-rendered drawing or perform cold rendering:<\/p>\n<ul>\n<li>If a pre-rendered drawing is available, Aspose.Words uses it to render the <code>SmartArt<\/code> object.<\/li>\n<li>If pre-rendered drawing is missing, Aspose.Words implicitly performs cold rendering to render the <code>SmartArt<\/code> object.<\/li>\n<li>If a pre-rendered drawing is present but is incorrect, it is required to perform SmartArt cold rendering explicitly by calling <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/shape\/#updateSmartArtDrawing\">UpdateSmartArtDrawing<\/a> method.<\/li>\n<\/ul>\n<p>The following code example shows how to update drawings for all diagrams in the document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-UpdateSmartArtDrawing.java\"><\/script>\n\n<h2 id=\"support-for-standard-smartart-layouts\">Support for Standard SmartArt Layouts<\/h2>\n<p>Currently, only a limited number of standard Microsoft Word SmartArt layouts are supported. Also, some of these layouts are supported partially, meaning that significant nodes and shapes of the diagram are rendered, but there may be differences between Microsoft Word and Aspose.Words diagram layout.<\/p>\n<p>The table below lists the fully and partially supported layouts:<\/p>\n<table>\n<thead>\n<tr>\n<th>SmartArt Layouts Group<\/th>\n<th>Fully supported layouts<\/th>\n<th>Partially supported layouts<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>List<\/code><\/td>\n<td><ul><li>Basic Block List<\/li><li>Alternating Hexagons<\/li><li>Vertical Bullet List<\/li><li>Vertical Box List<\/li><li>Varying Width List<\/li><li>Horizontal Bullet List<\/li><li>Grouped List<\/li><li>Vertical Block List<\/li><li>Vertical Chevron List<\/li><li>Vertical Arrow List<\/li><li>Trapezoid List<\/li><li>Table List<\/li><li>Pyramid List<\/li><li>Target List<\/li><\/ul><\/td>\n<td><ul><li>Lined List<\/li><li>Vertical Bracket List<\/li><li>Tab List<\/li><li>Stacked List<\/li><li>Vertical Accent List<\/li><li>Vertical Circle List<\/li><\/ul><\/td>\n<\/tr>\n<tr>\n<td><code>Process<\/code><\/td>\n<td><ul><li>Basic Process<\/li><li>Accent Process<\/li><li>Continuous Block Process<\/li><li>Increasing Arrow Process<\/li><li>Converging Text<\/li><li>Basic Timeline<\/li><li>Basic Chevron Process<\/li><li>Chevron Accent Process<\/li><li>Closed Chevron Process<\/li><li>Chevron List<\/li><li>Vertical Process<\/li><li>Staggered Process<\/li><li>Process List<\/li><li>Basic Bending Process<\/li><li>Repeating Bending Process<\/li><li>Detailed Process<\/li><li>Upward Arrow<\/li><li>Descending Process<\/li><li>Circular Bending Process<\/li><\/ul><\/td>\n<td><ul><li>Step Up Process<\/li><li>Step Down Process<\/li><li>Alternating Flow<\/li><li>Increasing Circle Process<\/li><li>Pie Process<\/li><li>Interconnected Block Process<\/li><li>Process Arrows<\/li><li>Circle Accent Timeline<\/li><li>Circle Process<\/li><li>Sub Step Process<\/li><li>Phased Process<\/li><li>Random to Result Process<\/li><li>Circle Arrow Process<\/li><\/ul><\/td>\n<\/tr>\n<tr>\n<td><code>Cycle<\/code><\/td>\n<td>\u2013<\/td>\n<td><ul><li>Segmented Cycle<\/li><li>Hexagon Radial<\/li><\/ul><\/td>\n<\/tr>\n<tr>\n<td><code>Hierarchy<\/code><\/td>\n<td>\u2013<\/td>\n<td><ul><li>Table Hierarchy<\/li><li>Architecture Layout<\/li><\/ul><\/td>\n<\/tr>\n<tr>\n<td><code>Relationship<\/code><\/td>\n<td><ul><li>Balance<\/li><li>Funnel<\/li><li>Gear<\/li><li>Plus And Minus<\/li><li>Arrow Ribbon<\/li><li>Counterbalance Arrows<\/li><li>Opposing Arrows<\/li><li>Nested Target<\/li><li>Basic Target<\/li><li>Basic Pie<\/li><li>Basic Venn<\/li><li>Stacked Venn<\/li><li>Interconnected Ring<\/li><\/ul><\/td>\n<td><ul><li>Circle Relationship<\/li><li>Opposing Ideas<\/li><li>Equation<\/li><li>Vertical Equation<\/li><li>Linear Venn<\/li><\/ul><\/td>\n<\/tr>\n<tr>\n<td><code>Matrix<\/code><\/td>\n<td><ul><li>Basic Matrix<\/li><li>Titled Matrix<\/li><li>Grid Matrix<\/li><li>Cycle Matrix<\/li><\/ul><\/td>\n<td>\u2013<\/td>\n<\/tr>\n<tr>\n<td><code>Pyramid<\/code><\/td>\n<td>\u2013<\/td>\n<td><ul><li>Segmented Pyramid<\/li><\/ul><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2 id=\"comparison-of-smartart-rendering-in-asposewords-and-microsoft\">Comparison of SmartArt Rendering in Aspose.Words and Microsoft<\/h2>\n<p>The table below shows example pictures of Aspose.Words Cold Rendering of some standard layouts compared to Microsoft Word output:<\/p>\n<table>\n<thead>\n<tr>\n<th><\/th>\n<th><strong>Aspose.Words<\/strong><\/th>\n<th><strong>Microsoft Word<\/strong><\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><strong>Basic Process<\/strong><\/td>\n<td><img src=\"basic-process-aspose.png\" alt=\"basic_process_aspose\"\/><\/td>\n<td><img src=\"basic-process-word.png\" alt=\"basic_process_word\"\/><\/td>\n<\/tr>\n<tr>\n<td><strong>Circular Bending Process<\/strong><\/td>\n<td><img src=\"circular-bending-process-aspose.png\" alt=\"circular_bending_process_aspose\"\/><\/td>\n<td><img src=\"circular-bending-process-word.png\" alt=\"circular_bending_process_word\"\/><\/td>\n<\/tr>\n<tr>\n<td><strong>Repeating Bending Process<\/strong><\/td>\n<td><img src=\"repearing-bending-process-aspose.png\" alt=\"repearing_bending_process_aspose\"\/><\/td>\n<td><img src=\"repearing-bending-process-word.png\" alt=\"repearing_bending_process_word\"\/><\/td>\n<\/tr>\n<tr>\n<td><strong>Trapezoid List<\/strong><\/td>\n<td><img src=\"trapezoid-list-aspose.png\" alt=\"trapezoid_list_aspose\"\/><\/td>\n<td><img src=\"trapezoid-list-word.png\" alt=\"trapezoid_list_word\"\/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I force Aspose.Words to perform cold rendering when the pre\u2011rendered SmartArt drawing is incorrect?<br>\n<strong>A:<\/strong> Call the <code>Shape.updateSmartArtDrawing()<\/code> method on each <code>Shape<\/code> that contains a SmartArt object. This forces Aspose.Words to discard the existing drawing and lay out the SmartArt anew.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is cold rendering performed automatically if the pre\u2011rendered drawing is missing?<br>\n<strong>A:<\/strong> Yes. When Aspose.Words loads a document and detects that a SmartArt object has no associated drawing, it automatically performs cold rendering without any additional code.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Which SmartArt layout groups are fully supported by Aspose.Words for Java?<br>\n<strong>A:<\/strong> The fully supported groups are <strong>List<\/strong>, <strong>Process<\/strong>, <strong>Relationship<\/strong>, and <strong>Matrix<\/strong>. The documentation table lists the exact layouts within each group.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I update the drawings for all SmartArt objects in a document with a single call?<br>\n<strong>A:<\/strong> Iterate through all <code>Shape<\/code> nodes, check <code>shape.isSmartArt()<\/code>, and invoke <code>shape.updateSmartArtDrawing()<\/code>. The sample code in the article demonstrates this pattern.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I determine programmatically whether a SmartArt object already has a pre\u2011rendered drawing?<br>\n<strong>A:<\/strong> Yes. Use <code>shape.getSmartArt().hasSmartArtDrawing()<\/code> (or the equivalent property in the Java API) to check if the drawing exists before deciding whether to call <code>updateSmartArtDrawing()<\/code>.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Create BarCode in Java","link":"https:\/\/docs.aspose.com\/words\/java\/how-to-generate-a-custom-barcode-image-for-displaybarcode-field\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/how-to-generate-a-custom-barcode-image-for-displaybarcode-field\/","description":"\n        \n        \n        <p>A barcode is a visual representation of data in the form of parallel lines or patterns. Barcodes are widely used in various industries such as retail, logistics, healthcare, banking, and many others.<\/p>\n<p>Microsoft Word allows users to embed barcodes directly into documents using fields. Users can insert a specific type of barcode, such as a QR code or a linear barcode, using the <a href=\"https:\/\/learn.microsoft.com\/en-us\/openspecs\/office_standards\/ms-oi29500\/cbc893c0-9683-416d-84c6-407a92451c19\">BARCODE<\/a> field.<\/p>\n<p>In this article, we will look at how the BARCODE field is implemented in Aspose.Words and how Aspose.Words allows users to work with Word documents to which a barcode has already been added.<\/p>\n<h2 id=\"barcode-types-supported-by-asposewords\">Barcode Types Supported by Aspose.Words<\/h2>\n<p>Aspose.Words supports various types of barcodes. The barcode type is passed as a string value in the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/barcodeparameters\/#getBarcodeType\">BarcodeType<\/a> property.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nSince working with barcodes within the functionality of Aspose.Words is limited, the user can use any library, including Aspose.Barcode, or write his own rendering to work with barcodes. You can learn more about the types of barcodes <a href=\"https:\/\/docs.aspose.com\/barcode\/java\/barcode-types\/\">supported by Aspose.BarCode<\/a>.\n<\/div>\n\n<p>When saving to Word formats that support barcodes, you can use any type of barcode that is <a href=\"https:\/\/support.microsoft.com\/en-us\/office\/field-codes-displaybarcode-6d81eade-762d-4b44-ae81-f9d3d9e07be3-4b44-ae81-f9d3d9e07be3\">supported by Microsoft Word<\/a>. If an incorrect type of barcode was passed, Word will display an error.<\/p>\n<p>When saving to other formats, such as PDF, Aspose.Words delegates barcode rendering to the user code, so the user is limited to the barcode types of their implementation or library used.<\/p>\n<h2 id=\"insert-a-barcode-into-a-document-or-load-a-document-with-an-added-barcode\">Insert a Barcode into a Document or Load a Document with an Added Barcode<\/h2>\n<p>Aspose.Words provides the ability to:<\/p>\n<ol>\n<li>Programmatically insert a barcode into a document using the <a href=\"https:\/\/support.microsoft.com\/en-au\/office\/field-codes-displaybarcode-6d81eade-762d-4b44-ae81-f9d3d9e07be3\">DisplayBarcode<\/a> and <a href=\"https:\/\/support.microsoft.com\/en-au\/office\/field-codes-mergebarcode-812fc43f-cb53-4782-8f9f-290ed08d34f3\">MergeBarcode<\/a> field codes<\/li>\n<li>Or load a Word document with barcodes already inserted into it for further work<\/li>\n<\/ol>\n<p>Aspose.Words has an interface for generating custom barcodes that makes it easy to use <a href=\"https:\/\/products.aspose.com\/words\/java\/\">Aspose.Words<\/a> and <a href=\"https:\/\/products.aspose.com\/barcode\/java\/\">Aspose.BarCode<\/a> together to render barcode images in output documents. For example, you can create a DOC, OOXML, or RTF document and add DISPLAYBARCODE field to it using Aspose.Words. Or you can load a DOC, OOXML or RTF document with DISPLAYBARCODE field already existing in it and provide your implementation of custom barcode generator.<\/p>\n<p>A typical DISPLAYBARCODE field has the following syntax:<\/p>\n<p><code>{ DISPLAYBARCODE &quot;SomeData&quot; QR \\h 720 }<\/code><\/p>\n<p>Below is an example code generator using the Aspose.Words and Aspose.BarCode APIs. This example shows how to insert barcode images at DISPLAYBARCODE field position in a Word document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/689e63b98de2dcbb12dffc37afbe9067.js?file=barcode-generator.java\"><\/script>\n\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/689e63b98de2dcbb12dffc37afbe9067.js?file=custom-barcode-generator.java\"><\/script>\n\n<p>You can also save the document with the loaded or newly inserted barcode in fixed page formats such as PDF, XPS, etc. The following code example shows how to save a Word document to PDF format:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/b237846932dfcde42358bd0c887661a5.js?file=docx-to-pdf.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nFor more information about converting documents from one format to another, see  the <a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/convert-a-document\/\">Convert a Document<\/a> documentation section.\n<\/div>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can also use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/ibarcodegenerator\/\">IBarcodeGenerator<\/a> interface to convert barcodes embedded in Word documents into images. The resulting images can be extracted from the document \u2013 see the Working with Images article for details.\n<\/div>\n\n<h2 id=\"specify-barcode-options\">Specify Barcode Options<\/h2>\n<p>When working with barcodes, you can set some additional properties. Aspose.Words provides you with the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/barcodeparameters\/\">BarcodeParameters<\/a> class \u2013 class for barcode parameters to pass-through to BarcodeGenerator.<\/p>\n<p>Aspose.Words supports embedded 96 ppi resolution for images generated with <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/ibarcodegenerator\/\">IBarcodeGenerator<\/a>, which limits the minimum size of a barcode image. To address this, developers can manually insert barcode images with the target resolution into a Word document and save them in the required format. For more details and examples on working with barcodes, see the article <a href=\"https:\/\/docs.aspose.com\/barcode\/java\/read-barcode-from-word-document\/\">Read Barcodes from Word Documents<\/a>.<\/p>\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I programmatically insert a <code>DISPLAYBARCODE<\/code> field into a Word document?<br>\n<strong>A:<\/strong> Create a <code>DocumentBuilder<\/code>, use <code>InsertField<\/code> with the field code syntax, e.g.<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"n\">Document<\/span> <span class=\"n\">doc<\/span> <span class=\"o\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Document<\/span><span class=\"o\">();<\/span>\n<span class=\"n\">DocumentBuilder<\/span> <span class=\"n\">builder<\/span> <span class=\"o\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">DocumentBuilder<\/span><span class=\"o\">(<\/span><span class=\"n\">doc<\/span><span class=\"o\">);<\/span>\n<span class=\"n\">builder<\/span><span class=\"o\">.<\/span><span class=\"na\">insertField<\/span><span class=\"o\">(<\/span><span class=\"s\">&#34;{ DISPLAYBARCODE \\&#34;1234567890\\&#34; CODE128 }&#34;<\/span><span class=\"o\">);<\/span>\n<\/code><\/pre><\/div><p>After inserting the field, you can assign a custom <code>IBarcodeGenerator<\/code> implementation to render the barcode when the document is saved.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What is the purpose of the <code>IBarcodeGenerator<\/code> interface?<br>\n<strong>A:<\/strong> <code>IBarcodeGenerator<\/code> lets you supply your own barcode rendering logic. Implement the <code>generateBarcodeImage(BarcodeParameters parameters)<\/code> method to return a <code>java.awt.image.BufferedImage<\/code>. Aspose.Words calls this method for each <code>DISPLAYBARCODE<\/code> field when saving to formats that do not support native barcode rendering (e.g., PDF).<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Which barcode types are supported by Aspose.Words out\u2011of\u2011the\u2011box?<br>\n<strong>A:<\/strong> The <code>BarcodeParameters.getBarcodeType()<\/code> property accepts any barcode type that Microsoft Word recognises (QR, CODE128, EAN13, etc.). If you need additional types, use Aspose.BarCode or another library inside your <code>IBarcodeGenerator<\/code> implementation.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I control the resolution or size of the generated barcode image?<br>\n<strong>A:<\/strong> Set the <code>Resolution<\/code> property on <code>BarcodeParameters<\/code> (default 96\u202fppi). You can also specify width and height in the field switches (<code>\\h<\/code> for height, <code>\\w<\/code> for width). Example: <code>{ DISPLAYBARCODE &quot;Data&quot; QR \\h 720 \\w 300 }<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Do I need a license to use barcode generation with Aspose.Words for Java?<br>\n<strong>A:<\/strong> Yes. To remove evaluation limitations and enable full functionality (including custom <code>IBarcodeGenerator<\/code>), apply a valid Aspose.Words for Java license via <code>License license = new License(); license.setLicense(&quot;Aspose.Words.Java.lic&quot;);<\/code>. The same license also covers any Aspose.BarCode usage if you integrate the two libraries.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Ole Objects","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-ole-objects\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-ole-objects\/","description":"\n        \n        \n        <p>OLE stands for &ldquo;Object Linking and Embedding&rdquo;. This is the technology by which users can work with documents containing &ldquo;objects&rdquo; created or edited by third-party applications. That is, OLE allows an application to export these &ldquo;objects&rdquo; to another application for editing, and then import them back with some additional content.<\/p>\n<p>In this article, we will talk about inserting an OLE object and setting its properties into a document.<\/p>\n<h2 id=\"insert-ole-object\">Insert Ole Object<\/h2>\n<p>If you want OLE Object, call the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertOleObject-java.io.InputStream-java.lang.String-boolean-java.io.InputStream\">InsertOleObject<\/a> method and pass it the <strong>ProgId<\/strong> explicitly with other parameters.<\/p>\n<p>The following code example shows how to insert OLE Object into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderInsertOleObject-DocumentBuilderInsertOleObject.java\"><\/script>\n\n<h3 id=\"set-file-name-and-extension-when-inserting-ole-object\">Set File Name and Extension when Inserting OLE Object<\/h3>\n<p>OLE package is a legacy and &ldquo;undocumented&rdquo; way to store embedded objects if an OLE handler is unknown.<\/p>\n<p>Early Windows versions such as Windows 3.1, 95, and 98 had a Packager.exe application that could be used to embed any type of data into the document. This application is now excluded from Windows, but Microsoft Word and other applications still use it to embed data if the OLE handler is missing or unknown. The <code>OlePackage<\/code> class allows users to access the OLE Package properties.<\/p>\n<p>The following code example shows how to\u00a0set the file name, extension, and display name for OLE Package:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderInsertElements-InsertOleObjectwithOlePackage.java\"><\/script>\n\n<h3 id=\"get-access-to-ole-object-raw-data\">Get Access to OLE Object Raw Data<\/h3>\n<p>Users can access OLE object data using various properties and methods of the <code>OleFormat<\/code> class. For example, it is possible to get the <code>OLE<\/code> object raw data or the path and name of a source file for the linked OLE object.<\/p>\n<p>The following code example shows how to get OLE Object raw data using\u00a0the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/oleformat\/#getRawData\">GetRawData<\/a> method:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderInsertElements-GetAccessToOLEObjectRawData.java\"><\/script>\n\n<h3 id=\"insert-ole-object-as-an-icon\">Insert OLE Object as an Icon<\/h3>\n<p>OLE objects can also be inserted into documents as images.<\/p>\n<p>The following code example shows how to insert OLE Object as an icon. For this purpose, the <strong>DocumentBuilder<\/strong> class exposes the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertOleObjectAsIcon-java.io.InputStream-java.lang.String-java.lang.String-java.lang.String\">InsertOleObjectAsIcon<\/a> method.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-InsertOLEObjectAsIcon.java\"><\/script>\n\n<p>The following code example shows how to inserts an embedded OLE object as an icon from a stream into the document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Shapes-WorkingWithShapes-InsertOLEObjectAsIconUsingStream.java\"><\/script>\n\n<h2 id=\"insert-online-video\">Insert Online Video<\/h2>\n<p>Online video can be inserted into Word document from the <em>&ldquo;Insert&rdquo; &gt; &ldquo;Online Video&rdquo;<\/em> tab. You can insert an online video into a document at the current location by calling the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertOnlineVideo-java.lang.String-double-double\">InsertOnlineVideo<\/a> method:<\/p>\n<p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> class introduces four overloads of this method. The first one works with the most popular video resources and takes the <code>URL<\/code> of the video as a parameter. For example, the first overload supports simple insertion of online videos from <a href=\"https:\/\/www.youtube.com\/\">YouTube<\/a> and <a href=\"https:\/\/vimeo.com\/\">Vimeo<\/a> resources.<\/p>\n<p>The following code example shows how to insert an online video from <em>Vimeo<\/em> into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Video-InsertOnlineVideo-InsertOnlineVideo.java\"><\/script>\n\n<p>The second overload works with all other video resources and takes embedded HTML code as a parameter. The HTML code for embedding a video may vary depending on the provider, so contact the respective provider for details.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nPlease note that the document will be automatically optimized for MS Word 2013 to show video.\n<\/div>\n\n<p>The following code example shows how to insert an online video into a document using such HTML code:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-Video-InsertOnlineVideo-InsertOnlineVideoWithEmbedHtml.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I insert an OLE object from a file stream in Java?<br>\n<strong>A:<\/strong> Use <code>DocumentBuilder.insertOleObject(InputStream stream, String progId, boolean isLinked, InputStream iconStream)<\/code>. Provide the object\u2019s ProgID (e.g., <code>&quot;Word.Document&quot;<\/code>), the data stream, and optionally an icon stream.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I set a custom file name, extension, and display name for an OLE package?<br>\n<strong>A:<\/strong> Create an <code>OlePackage<\/code> instance, then call <code>setFileName()<\/code>, <code>setExtension()<\/code>, and <code>setDisplayName()<\/code> before inserting it with <code>DocumentBuilder.insertOleObject<\/code>.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What is the way to retrieve the raw binary data of an embedded OLE object?<br>\n<strong>A:<\/strong> Obtain the <code>OleFormat<\/code> object from the OLE node (<code>OleFormat ole = (OleFormat)node;<\/code>) and call <code>ole.getRawData()<\/code> to get a byte array containing the original data.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I insert an OLE object as an icon rather than as embedded content?<br>\n<strong>A:<\/strong> Use <code>DocumentBuilder.insertOleObjectAsIcon(InputStream stream, String progId, String iconFileName, String iconDisplayName)<\/code>; this inserts the object and displays the specified icon image.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I detect whether a document contains any OLE objects?<br>\n<strong>A:<\/strong> Iterate through the document\u2019s OLE nodes:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"n\">NodeCollection<\/span> <span class=\"n\">oleNodes<\/span> <span class=\"o\">=<\/span> <span class=\"n\">doc<\/span><span class=\"o\">.<\/span><span class=\"na\">getChildNodes<\/span><span class=\"o\">(<\/span><span class=\"n\">NodeType<\/span><span class=\"o\">.<\/span><span class=\"na\">OBJECT<\/span><span class=\"o\">,<\/span> <span class=\"kc\">true<\/span><span class=\"o\">);<\/span>\n<span class=\"k\">for<\/span> <span class=\"o\">(<\/span><span class=\"n\">Node<\/span> <span class=\"n\">node<\/span> <span class=\"o\">:<\/span> <span class=\"n\">oleNodes<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span>\n    <span class=\"k\">if<\/span> <span class=\"o\">(<\/span><span class=\"n\">node<\/span> <span class=\"k\">instanceof<\/span> <span class=\"n\">OleFormat<\/span><span class=\"o\">)<\/span> <span class=\"o\">{<\/span>\n        <span class=\"c1\">\/\/ OLE object found\n<\/span><span class=\"c1\"><\/span>    <span class=\"o\">}<\/span>\n<span class=\"o\">}<\/span>\n<\/code><\/pre><\/div><p>If the collection is non\u2011empty, the document includes OLE objects.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Fields in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-fields\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-fields\/","description":"\n        \n        \n        <p><strong>Fields<\/strong> in a document are like placeholders where useful data can be inserted. For example, a field can be a page reference, formula, or a Mail Merge field.<\/p>\n<p>In a document created or edited with Aspose.Words, as in a Microsoft Word document, a field consists of a field code and a field result. The field code is an instruction about how the field result needs to be updated or calculated. An application that processes a document and encounters a field should interpret the instructions contained in the field code and update the field result with a new value.<\/p>\n<p>In Aspose.Words, fields are represented by various classes, most of whose names begin with &ldquo;Field&rdquo;. Articles in this documentation section explain how to use Aspose.Words classes to manipulate document fields programmatically.<\/p>\n\n      "},{"title":"Java: Working with Form Fields in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-form-fields\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-form-fields\/","description":"\n        \n        \n        <p>A document that contains fill-in blanks (fields) is known as a form. For example, you can create a registration form in Microsoft Word that uses drop-down lists from which users can select entries. The <code>Form<\/code> field is a location where a particular type of data, such as a name or address, is stored. Form fields in Microsoft Word include text input, combobox and checkbox.<\/p>\n<p>You can use form fields in your project to &ldquo;communicate&rdquo; with your users. For example, you create a document whose content is protected, but only form fields are editable. The users can enter the data in the form fields and submit the document. Your application that uses Aspose.Words can retrieve data from the form fields and process it.<\/p>\n<p>Placing form fields into the document via code is easy. <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/\">DocumentBuilder<\/a> has special methods for inserting them, one for each form field type.\u00a0Each of the methods accepts a string parameter representing the name of the form field. The name can be an empty string. If however you specify a name for the form field, then a bookmark is automatically created with the same name.<\/p>\n<h2 id=\"insert-form-fields\">Insert Form Fields<\/h2>\n<p>Form fields are a particular case of Word fields that allows &ldquo;interaction&rdquo; with the user. Form fields in Microsoft Word include textbox, combo box and checkbox.<\/p>\n<p><strong>DocumentBuilder<\/strong>\u00a0provides special methods to insert each type of form field into the document: <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertCheckBox-java.lang.String-boolean-boolean-int\">insertTextInput<\/a>, <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertCheckBox-java.lang.String-boolean-boolean-int\">insertCheckBox<\/a> or <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentbuilder\/#insertCheckBox-java.lang.String-boolean-int\">insertComboBox<\/a>.<\/p>\n<p>The following code example shows how to insert a combobox form field into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-fields-InsertFormFields-InsertFormFields.java\"><\/script>\n\n<h3 id=\"insert-a-text-input\">Insert a Text Input<\/h3>\n<p>Use the <strong>insertTextInput<\/strong>\u00a0method to insert a textbox into the document.<\/p>\n<p>The following code example shows how to insert a text input form field into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderInsertTextInputFormField-DocumentBuilderInsertTextInputFormField.java\"><\/script>\n\n<h3 id=\"insert-a-check-box\">Insert a Check Box<\/h3>\n<p>Call\u00a0<strong>insertCheckBox<\/strong>\u00a0to insert a checkbox into the document.<\/p>\n<p>The following code example shows how to insert a checkbox form field into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderInsertCheckBoxFormField-DocumentBuilderInsertCheckBoxFormField.java\"><\/script>\n\n<h3 id=\"insert-a-combo-box\">Insert a Combo Box<\/h3>\n<p>Call\u00a0<strong>insertComboBox<\/strong>\u00a0to insert a combobox into the document.<\/p>\n<p>The following code example shows how to insert a Combobox form field into a document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-DocumentBuilderInsertComboBoxFormField-DocumentBuilderInsertComboBoxFormField.java\"><\/script>\n\n<h2 id=\"obtain-form-fields\">Obtain Form Fields<\/h2>\n<p>A collection of form fields is represented by the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/formfieldcollection\/\">FormFieldCollection<\/a> class that can be retrieved using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/range\/#getFormFields\">Range.getFormFields<\/a> property. This means that you can obtain form fields contained in any document node including the document itself.<\/p>\n<p>The following code example shows how to get a collection of form fields:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-fields-FormFieldsGetFormFieldsCollection-FormFieldsGetFormFieldsCollection.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of the following examples from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Form%20fields.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<p>You can get a particular form field by its index or name.<\/p>\n<p>The following code example shows how to access form fields:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-fields-FormFieldsGetByName-FormFieldsGetByName.java\"><\/script>\n\n<p>The <strong>FormField<\/strong> properties allow you to work with form field name, type, and result.<\/p>\n<p>The following code example shows how to work with form field name, type, and result:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-fields-FormFieldsWorkWithProperties-FormFieldsWorkWithProperties.java\"><\/script>\n\n\n      "},{"title":"Java: Working with Content Control SDT in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-content-control-sdt\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-content-control-sdt\/","description":"\n        \n        \n        <p>In Microsoft Word, you can create a form by starting with a template and adding content controls, including checkboxes, text boxes, date pickers, and drop\u2011down lists.\u00a0In Aspose.Words, a Structured Document Tag or content control from any document loaded into Aspose.Words is imported as a StructuredDocumentTag node.\u00a0Structured document tags (SDT or content control) allow embedding customer\u2011defined semantics as well as its behaviour and appearance into a document.<\/p>\n<p>StructuredDocumentTag can occur in a document in the following places:<\/p>\n<ul>\n<li>Block-level - Among paragraphs and tables, as a child of a Body, HeaderFooter, Comment, Footnote or a Shape node.<\/li>\n<li>Row-level - Among rows in a table, as a child of a Table node.<\/li>\n<li>Cell-level - Among cells in a table row, as a child of a Row node.<\/li>\n<li>Inline-level - Among inline content inside, as a child of a Paragraph.<\/li>\n<li>Nested inside another StructuredDocumentTag.<\/li>\n<\/ul>\n<h2 id=\"inserting-content-controls-into-a-document\">Inserting Content Controls into a Document<\/h2>\n<p>In this version of Aspose.Words, the following types of SDT or content control can be created:<\/p>\n<ul>\n<li>Checkbox<\/li>\n<li>DropDownList<\/li>\n<li>ComboBox<\/li>\n<li>Date<\/li>\n<li>BuildingBlockGallery<\/li>\n<li>Group<\/li>\n<li><code>Picture<\/code><\/li>\n<li>RichText<\/li>\n<li>PlainText<\/li>\n<\/ul>\n<p>The following code example shows\u00a0how to create content control of type checkbox:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-CheckBoxTypeContentControl-CheckBoxTypeContentControl.java\"><\/script>\n\n<p>The following code example shows\u00a0how to create content control of type rich text box:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-RichTextBoxContentControl-RichTextBoxContentControl.java\"><\/script>\n\n<p>The following code example shows\u00a0how to create content control of type combo box:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ComboBoxContentControl-ComboBoxContentControl.java\"><\/script>\n\n<h2 id=\"how-to-update-content-controls\">How to Update Content Controls<\/h2>\n<p>This section explains how to update the values of SDT or content control programmatically.<\/p>\n<p>The following code example shows\u00a0how to set the current state of the checkbox:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-SetCurrentStateOfCheckBox-SetCurrentStateOfCheckBox.java\"><\/script>\n\n<p>The following code example shows\u00a0how to modify content controls of type plain text box, drop\u2011down list and picture:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ModifyContentControls-ModifyContentControls.java\"><\/script>\n\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nYou can download the sample file of these examples from <a href=\"https:\/\/github.com\/aspose-words\/Aspose.Words-for-Java\/blob\/master\/Examples\/Data\/Structured%20document%20tags.docx\">Aspose.Words GitHub<\/a>.\n<\/div>\n\n<h2 id=\"binding-content-control-to-custom-xml-parts\">Binding Content Control to Custom XML Parts<\/h2>\n<p>You can bind content controls with XML data (<em>custom XML part<\/em>) in Word documents.\u00a0<\/p>\n<p>The following code example shows how to\u00a0bind content control to custom XML parts:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-BindingContentControlwithXML-BindingContentControlwithXML.java\"><\/script>\n\n<h2 id=\"clear-contents-of-a-content-control\">Clear Contents of a Content Control<\/h2>\n<p>You can clear the contents of a content control with displaying a placeholder. <strong>StructuredDocumentTag.clear()<\/strong> method clears contents of this structured document tag and displays a placeholder if it is defined. However, It is not possible to clear the contents of a content control if it has revisions. If a content control has no placeholder, five spaces are inserted like in MS Word (except repeating sections, repeating section items, groups, check\u2011boxes, citations). If a content control is mapped to custom XML, the referenced XML node is cleared.<\/p>\n<p>The following code example shows how to clear the content of content control:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-ClearContentsControl-ClearContentsControl.java\"><\/script>\n\n<h2 id=\"change-content-control-background-and-border-colors\">Change Content Control Background and Border Colors<\/h2>\n<p>The <code>StructuredDocumentTag.Color<\/code> property allows you to get or set the color of content control. The color affects content control in two situations:<\/p>\n<ol>\n<li>MS Word highlights the background of the content control when the mouse moves over the content control. This helps to identify the content control. The color of highlighting is a bit &ldquo;softer&rdquo; than the\u00a0<em>Color<\/em>. For example, MS Word highlights the background with the pink color, when\u00a0<em>Color<\/em>\u00a0is Red.<\/li>\n<li>When you interact (editing, picking etc) with the content control, the border of content control is colored with the\u00a0<em>Color<\/em>.<\/li>\n<\/ol>\n<p>The following code example shows\u00a0how to change the color of content control:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-StructuredDocumentTag-WorkingWithStructuredDocumentTag-SetContentControlColor.java\"><\/script>\n\n<h2 id=\"how-to-set-style-to-format-text-typed-into-the-content-control\">How to Set Style to Format Text Typed into the Content Control<\/h2>\n<p>If you want to set the style of content control, you can use <code>StructuredDocumentTag.Style<\/code>\u00a0or <code>StructuredDocumentTag.StyleName<\/code> properties. When you type the text into content control in the output document, the typed text will have the style &ldquo;Quote&rdquo;.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nNote that only Linked and Character styles can be applied to content control. An InvalidOperationException (&ldquo;Cannot apply this style to the SDT&rdquo;) is thrown when a style that exists but is not Linked or Character style is being applied.\n<\/div>\n\n<p>The following code example shows how to set the style of content control:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-StructuredDocumentTag-WorkingWithStructuredDocumentTag-setContentControlStyle.java\"><\/script>\n\n<h2 id=\"working-with-repeating-section-content-control\">Working with Repeating Section Content Control<\/h2>\n<p>The repeating section content control allows repeating the content contained within it. Using Aspose.Words, the\u00a0structured document tag nodes of the repeating section and repeating section item types can be created and for this purpose,\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words.SdtType\/\">SdtType enumeration type<\/a>\u00a0provides\u00a0REPEATING_SECTION_ITEM\u00a0member.<\/p>\n<p>The following code example shows\u00a0how to bind a repeating section content control to a table:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-StructuredDocumentTag-WorkingWithStructuredDocumentTag-CreatingTableRepeatingSectionMappedToCustomXmlPart.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I create a checkbox content control in Java?<br>\n<strong>A:<\/strong> Instantiate a <code>StructuredDocumentTag<\/code> with <code>SdtType.CHECKBOX<\/code>, set its properties (e.g., title, placeholder), and insert it into the desired node (e.g., <code>Document.getFirstSection().getBody().appendChild(structuredDocumentTag);<\/code>).<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I set or read the checked state of a checkbox content control?<br>\n<strong>A:<\/strong> Use the <code>StructuredDocumentTag.setChecked(boolean)<\/code> method to set the state and <code>StructuredDocumentTag.isChecked()<\/code> to read the current state.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I bind a content control to a custom XML part?<br>\n<strong>A:<\/strong> Create a <code>CustomXmlPart<\/code>, add it to the document (<code>document.getCustomXmlParts().add(customXmlPart);<\/code>), then call <code>structuredDocumentTag.setXmlMapping(customXmlPart, &quot;\/Root\/Element&quot;, null);<\/code> to map the control to the XML node.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I change the background or border color of a content control?<br>\n<strong>A:<\/strong> Set the <code>StructuredDocumentTag.setColor(java.awt.Color)<\/code> property. The color is used for the hover background and the border when the control is active.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I specify the display format for a date content control?<br>\n<strong>A:<\/strong> Use <code>structuredDocumentTag.setDateDisplayFormat(&quot;MM\/dd\/yyyy&quot;);<\/code> to define the format string that Word will use to display the date value. This does not affect the underlying date value stored in the XML.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working With Control Characters","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-control-characters\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-control-characters\/","description":"\n        \n        \n        <p>Microsoft Word documents may contain various characters that have a special meaning. Normally they are used for formatting purposes and are not drawn in the normal mode. You can make them visible if you click the Show\/Hide Formatting Marks button located on the Standard toolbar.<\/p>\n<p>Sometimes you may need to add or remove characters to\/from the text. For instance, when obtaining text programmatically from the document, Aspose.Words preserves most of the control characters, so if you need to work with this text you should probably remove or replace the characters.<\/p>\n<p>The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/controlchar\/\">ControlChar<\/a> class is a repository for the constants that represent control characters often encountered in documents. It provides both char and string versions of the same constants. For example, string <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/controlchar\/#LINE-BREAK\">LineBreak<\/a> and char <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/controlchar\/#LINE-BREAK_CHAR\">LineBreakChar<\/a> has the same value.<\/p>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nUse this class whenever you want to deal with control characters.\n<\/div>\n\n<p>The following code example shows how to use control characters:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-document-UseControlCharacters-UseControlCharacters.java\"><\/script>\n\n\n      "},{"title":"Java: Working with VBA Macros in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-vba-macros\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-vba-macros\/","description":"\n        \n        \n        <p>Visual Basic for Applications (VBA) for Microsoft Word is a simple but powerful programming language that can be used to extend the functionality.\u00a0Aspose.Words API provides three classes\u00a0to get access to the VBA project source code:<\/p>\n<ul>\n<li>The\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/vbaproject\/\">VBAProject<\/a>\u00a0class provides access to the VBA project information<\/li>\n<li>The\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/vbamodulecollection\/\">VBAModulesCollection<\/a>\u00a0class returns the collection of VBA project modules<\/li>\n<li>The\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/vbamodule\/\">VbaModule<\/a>\u00a0class provides access to the VBA project module<\/li>\n<\/ul>\n<h2 id=\"create-a-vba-project\">Create a VBA Project<\/h2>\n<p>Aspose.Words API provides the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/document\/#getVbaProject\">VbaProject<\/a>\u00a0property to get or set VbaProject in the document.<\/p>\n<p>The following code example demonstrates how to create a VBA project and VBA Module along with basic properties e.g. Name and Type:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithVbaMacros-CreateVbaProject.java\"><\/script>\n\n<h2 id=\"read-macros\">Read Macros<\/h2>\n<p>Aspose.Words also provides users with the ability to read VBA macros.<\/p>\n<p>The following code example shows how to read VBA Macros from the document:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithVbaMacros-ReadVbaMacros.java\"><\/script>\n\n<h2 id=\"modify-macros\">Modify Macros<\/h2>\n<p>Using Aspose.Words, users can modify VBA macros.<\/p>\n<p>The following code example shows how to modify VBA Macros using the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/vbamodule\/#getSourceCode\">SourceCode<\/a> property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithVbaMacros-ModifyVbaMacros.java\"><\/script>\n\n<h2 id=\"clone-vba-project\">Clone VBA Project<\/h2>\n<p>With Aspose.Words it is also possible to clone VBA projects.<\/p>\n<p>The following code example demonstrates how to clone the VBA Project using the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/vbaproject\/#deepClone\">Clone<\/a>\u00a0property which creates a copy of the existing project:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithVbaMacros-CloneVbaProject.java\"><\/script>\n\n<h2 id=\"clone-vba-module\">Clone VBA Module<\/h2>\n<p>You can also clone VBA modules if needed.<\/p>\n<p>The following code example demonstrates how to clone the VBA Module using the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/vbaproject\/#deepClone\">Clone<\/a>\u00a0property which creates a copy of the existing project.\u00a0<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithVbaMacros-CloneVbaModule.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How do I apply an Aspose.Words license when working with VBA macros in Java?<br>\n<strong>A:<\/strong> Load the license file using <code>License license = new License(); license.setLicense(&quot;Aspose.Words.Java.lic&quot;);<\/code> before creating or loading any document. The license must be set once per application domain; otherwise, the library runs in evaluation mode and may add watermarks.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can Aspose.Words execute VBA macros embedded in a Word document?<br>\n<strong>A:<\/strong> No. Aspose.Words can read, modify, and clone VBA projects, but it does not execute VBA code. Execution of macros must be performed in Microsoft Word or another environment that supports VBA.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I read the source code of a specific VBA module?<br>\n<strong>A:<\/strong> Retrieve the module from the <code>VBAModulesCollection<\/code> and use the <code>getSourceCode()<\/code> method:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"n\">VbaModule<\/span> <span class=\"n\">module<\/span> <span class=\"o\">=<\/span> <span class=\"n\">document<\/span><span class=\"o\">.<\/span><span class=\"na\">getVbaProject<\/span><span class=\"o\">().<\/span><span class=\"na\">getModules<\/span><span class=\"o\">().<\/span><span class=\"na\">getByName<\/span><span class=\"o\">(<\/span><span class=\"s\">&#34;Module1&#34;<\/span><span class=\"o\">);<\/span>\n<span class=\"n\">String<\/span> <span class=\"n\">source<\/span> <span class=\"o\">=<\/span> <span class=\"n\">module<\/span><span class=\"o\">.<\/span><span class=\"na\">getSourceCode<\/span><span class=\"o\">();<\/span>\n<\/code><\/pre><\/div><\/li>\n<li>\n<p><strong>Q:<\/strong> What is the recommended way to modify the source code of a VBA macro?<br>\n<strong>A:<\/strong> Use the <code>setSourceCode(String)<\/code> method on the <code>VbaModule<\/code> instance after obtaining the module. Save the document afterwards to persist the changes.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I clone an entire VBA project or a single module?<br>\n<strong>A:<\/strong> Both <code>VbaProject<\/code> and <code>VbaModule<\/code> implement a deep clone method. Call <code>VbaProject clonedProject = originalProject.deepClone();<\/code> or <code>VbaModule clonedModule = originalModule.deepClone();<\/code> and assign the cloned object to the target document.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Markdown Features in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-markdown-features\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-markdown-features\/","description":"\n        \n        \n        <p>This topic discusses how to implement Markdown features using Aspose.Words. Markdown is a simple way to format plain text that can easily be converted to HTML. Aspose.Words supports\u00a0the following Markdown features:<\/p>\n<ul>\n<li>Headings<\/li>\n<li>Blockquotes<\/li>\n<li>Horizontal rules<\/li>\n<li>Bold emphasis<\/li>\n<li>Italic emphasis<\/li>\n<\/ul>\n<p>The Markdown feature implementation\u00a0mostly follows the <code>CommonMark<\/code> specification in Aspose.Words API and all the features are represented as corresponding styles or direct formatting. Which means that<\/p>\n<ul>\n<li>Bold and Italic are represented as <code>Font.Bold<\/code> and <code>Font.Italic<\/code>.\u00a0<\/li>\n<li>Headings are paragraphs with Heading 1 - Heading 6 styles.\u00a0<\/li>\n<li>Quotes are paragraphs with &ldquo;Quote&rdquo; in the style name.\u00a0<\/li>\n<li>HorizontalRule is a paragraph with a <code>HorizontalRule<\/code> shape.<\/li>\n<\/ul>\n\n\n<div class=\"alert alert-primary\" role=\"alert\">\n\nThere are nuances of translating Markdown to the Aspose.Words Document Object Model (DOM), described in the article <a href=\"https:\/\/docs.aspose.com\/words\/words\/java\/translate-markdown-to-document-object-model\/\">Translate Markdown to Document Object Model (DOM)<\/a>.\n<\/div>\n\n<h2 id=\"markdown-document-with-emphases\">Markdown Document with Emphases<\/h2>\n<p>This section demonstrates you how to produce a markdown document with emphases as given below:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">Markdown<\/span> <span class=\"n\">treats<\/span> <span class=\"n\">asterisks<\/span> <span class=\"p\">(*)<\/span> <span class=\"n\">and<\/span> <span class=\"n\">underscores<\/span> <span class=\"p\">(<\/span><span class=\"n\">_<\/span><span class=\"p\">)<\/span> <span class=\"k\">as<\/span> <span class=\"n\">indicators<\/span> <span class=\"n\">of<\/span> <span class=\"n\">emphasis<\/span><span class=\"p\">.<\/span>\n<span class=\"n\">You<\/span> <span class=\"n\">can<\/span> <span class=\"n\">write<\/span> <span class=\"p\">**<\/span><span class=\"n\">bold<\/span><span class=\"p\">**<\/span> <span class=\"n\">or<\/span> <span class=\"p\">*<\/span><span class=\"n\">italic<\/span><span class=\"p\">*<\/span> <span class=\"n\">text<\/span><span class=\"p\">.<\/span> \n<span class=\"n\">You<\/span> <span class=\"n\">can<\/span> <span class=\"n\">also<\/span> <span class=\"n\">write<\/span> <span class=\"p\">***<\/span><span class=\"n\">BoldItalic<\/span><span class=\"p\">***<\/span><span class=\"n\">text<\/span><span class=\"p\">.<\/span>\n<\/code><\/pre><\/div>\n<p>The following code snippet can be used to produce the above-given markdown document.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-MarkdownFeatures-WorkingWithMarkdownFeatures-MarkdownDocumentWithEmphases.java\"><\/script>\n\n<h2 id=\"markdown-document-with-headings\">Markdown Document with Headings<\/h2>\n<p>This section demonstrates you how to produce a markdown document with headings as given below:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">The<\/span> <span class=\"n\">following<\/span> <span class=\"n\">produces<\/span> <span class=\"n\">headings<\/span><span class=\"p\">:<\/span>\n<span class=\"err\">#<\/span> <span class=\"n\">Heading1<\/span>\n<span class=\"err\">##<\/span> <span class=\"n\">Heading2<\/span>\n<span class=\"err\">###<\/span> <span class=\"n\">Heading3<\/span>\n<span class=\"err\">####<\/span> <span class=\"n\">Heading4<\/span>\n<span class=\"err\">#####<\/span> <span class=\"n\">Heading5<\/span>\n<span class=\"err\">######<\/span> <span class=\"n\">Heading6<\/span>\n<span class=\"err\">#<\/span> <span class=\"p\">**<\/span><span class=\"n\">Bold<\/span> <span class=\"n\">Heading1<\/span><span class=\"p\">**<\/span>\n<\/code><\/pre><\/div>\n<p>The following code snippet can be used to produce the above given markdown document.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-MarkdownFeatures-WorkingWithMarkdownFeatures-MarkdownDocumentWithHeadings.java\"><\/script>\n\n<h2 id=\"markdown-document-with-block-quotes\">Markdown Document with Block Quotes<\/h2>\n<p>This section demonstrates you how to produce a markdown document with block quotes as given below:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">We<\/span> <span class=\"n\">support<\/span> <span class=\"n\">blockquotes<\/span> <span class=\"k\">in<\/span> <span class=\"n\">Markdown<\/span><span class=\"p\">:<\/span>\n<span class=\"p\">&gt;*<\/span><span class=\"n\">Lorem<\/span><span class=\"p\">*<\/span>\n<span class=\"p\">&gt;*<\/span><span class=\"n\">ipsum<\/span><span class=\"p\">*<\/span>\n<span class=\"p\">&gt;<\/span><span class=\"n\">The<\/span> <span class=\"n\">quotes<\/span> <span class=\"n\">can<\/span> <span class=\"n\">be<\/span> <span class=\"n\">of<\/span> <span class=\"n\">any<\/span> <span class=\"n\">level<\/span> <span class=\"n\">and<\/span> <span class=\"n\">can<\/span> <span class=\"n\">be<\/span> <span class=\"n\">nested<\/span><span class=\"p\">:<\/span>\n<span class=\"p\">&gt;&gt;&gt;<\/span><span class=\"n\">Quote<\/span> <span class=\"n\">level<\/span> <span class=\"m\">3<\/span>\n<span class=\"p\">&gt;&gt;&gt;<\/span>\n<span class=\"p\">&gt;&gt;&gt;&gt;<\/span><span class=\"n\">Nested<\/span> <span class=\"n\">quote<\/span> <span class=\"n\">level<\/span> <span class=\"m\">4<\/span>\n<span class=\"p\">&gt;<\/span>\n<span class=\"p\">&gt;*<\/span><span class=\"n\">Back<\/span> <span class=\"n\">to<\/span> <span class=\"n\">first<\/span> <span class=\"n\">level<\/span><span class=\"p\">*<\/span>\n<span class=\"p\">&gt;<\/span><span class=\"err\">###<\/span> <span class=\"n\">Headings<\/span> <span class=\"n\">are<\/span> <span class=\"n\">allowed<\/span> <span class=\"n\">inside<\/span> <span class=\"n\">Quotes<\/span>\n<span class=\"p\">&gt;<\/span>\n<\/code><\/pre><\/div>\n<p>The following code snippet can be used to produce the above given markdown document.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-MarkdownFeatures-WorkingWithMarkdownFeatures-MarkdownDocumentWithBlockQuotes.java\"><\/script>\n\n<h2 id=\"markdown-document-with-horizontal-rule\">Markdown Document with Horizontal Rule<\/h2>\n<p>This section demonstrates you how to produce a markdown document with Horizontal Rule as given below:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-csharp\" data-lang=\"csharp\"><span class=\"n\">We<\/span> <span class=\"n\">support<\/span> <span class=\"n\">Horizontal<\/span> <span class=\"n\">rules<\/span> <span class=\"p\">(<\/span><span class=\"n\">Thematic<\/span> <span class=\"n\">breaks<\/span><span class=\"p\">)<\/span> <span class=\"k\">in<\/span> <span class=\"n\">Markdown<\/span><span class=\"p\">:<\/span>\n<span class=\"p\">-----<\/span>\n<\/code><\/pre><\/div>\n<p>The following code snippet can be used to produce the above-given markdown document.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-MarkdownFeatures-WorkingWithMarkdownFeatures-MarkdownDocumentWithHorizontalRule.java\"><\/script>\n\n<h2 id=\"reading-a-markdown-document\">Reading a Markdown Document<\/h2>\n<p>The following code snippet shows you how to read a markdown document.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-MarkdownFeatures-WorkingWithMarkdownFeatures-ReadMarkdownDocument.java\"><\/script>\n\n<h2 id=\"specify-markdown-save-options\">Specify Markdown Save Options<\/h2>\n<p>Aspose.Words API provides\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/markdownsaveoptions\/\">MarkdownSaveOptions<\/a>\u00a0class to specify additional options while saving a document into the Markdown format.<\/p>\n<p>The following code example demonstrated how to specify various Markdown save options.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-MarkdownFeatures-WorkingWithMarkdownFeatures-SaveAsMD.java\"><\/script>\n\n<h2 id=\"how-to-align-content-inside-the-table-while-exporting-into-markdown\">How to Align Content Inside the Table while Exporting into Markdown<\/h2>\n<p>Aspose.Words API provides\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words.tablecontentalignment\/\">TableContentAlignment<\/a>\u00a0enumeration which defines alignment directions to align contents in tables while exporting into the Markdown document. The following code example demonstrates how to align content inside the table.<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-programming_documents-MarkdownFeatures-WorkingWithMarkdownFeatures-ExportIntoMarkdownWithTableContentAlignment.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> Which Markdown elements are currently supported by Aspose.Words for Java?<br>\n<strong>A:<\/strong> Aspose.Words for Java implements the CommonMark subset and supports headings (levels\u202f1\u20116), bold and italic emphasis, block quotes, horizontal rules, and tables (when using <code>TableContentAlignment<\/code>). Each element is mapped to a corresponding Word style or direct formatting.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I convert an existing Markdown file to a Word document (.docx) using Java?<br>\n<strong>A:<\/strong> Load the Markdown file with <code>MarkdownLoadOptions<\/code> and then save it as a DOCX. Example:<\/p>\n<div class=\"highlight\"><pre class=\"chroma\"><code class=\"language-java\" data-lang=\"java\"><span class=\"n\">Document<\/span> <span class=\"n\">doc<\/span> <span class=\"o\">=<\/span> <span class=\"k\">new<\/span> <span class=\"n\">Document<\/span><span class=\"o\">(<\/span><span class=\"s\">&#34;input.md&#34;<\/span><span class=\"o\">,<\/span> <span class=\"k\">new<\/span> <span class=\"n\">MarkdownLoadOptions<\/span><span class=\"o\">());<\/span>\n<span class=\"n\">doc<\/span><span class=\"o\">.<\/span><span class=\"na\">save<\/span><span class=\"o\">(<\/span><span class=\"s\">&#34;output.docx&#34;<\/span><span class=\"o\">);<\/span>\n<\/code><\/pre><\/div><p>The load options let you control how unknown tags are handled.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Can I preserve custom styles or additional formatting when converting Markdown to Word?<br>\n<strong>A:<\/strong> Yes. By customizing <code>MarkdownLoadOptions<\/code> you can map specific Markdown constructs to custom Word styles. Use the <code>setStyleIdentifier<\/code> or <code>setStyleName<\/code> methods to associate a Markdown element with a style defined in the target document.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I export a Word document to Markdown while controlling the alignment of table contents?<br>\n<strong>A:<\/strong> Use <code>MarkdownSaveOptions<\/code> together with the <code>TableContentAlignment<\/code> enumeration. Set the desired alignment (e.g., <code>TableContentAlignment.Center<\/code>) on the save options before calling <code>save<\/code>. This ensures table cells are rendered with the chosen alignment in the resulting Markdown file.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> Is it possible to enable additional CommonMark extensions, such as task lists or footnotes, during conversion?<br>\n<strong>A:<\/strong> Aspose.Words for Java follows the core CommonMark specification. Extensions like task lists or footnotes are not natively supported, but you can preprocess the Markdown (e.g., replace extension syntax with standard Markdown) before loading it with <code>MarkdownLoadOptions<\/code>.<\/p>\n<\/li>\n<\/ol>\n\n      "},{"title":"Java: Working with Text Document in Java","link":"https:\/\/docs.aspose.com\/words\/java\/working-with-text-document\/","pubDate":"Mon, 01 Jan 0001 00:00:00 +0000","guid":"https:\/\/docs.aspose.com\/words\/java\/working-with-text-document\/","description":"\n        \n        \n        <p>In this article, we will learn what options can be useful for working with a text document via Aspose.Words. Please note that this is not a complete list of available options, but only an example of working with some of them.<\/p>\n<h2 id=\"addbi-directional-marks\">Add\u00a0Bi-Directional Marks<\/h2>\n<p>You can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtsaveoptions\/#getAddBidiMarks\">AddBidiMarks<\/a> property to specify whether to add bi-directional marks before each BiDi run when exporting in plain text format. Aspose.Words inserts Unicode Character &lsquo;RIGHT-TO-LEFT MARK&rsquo; (U+200F) before each bi-directional Run in text. This option corresponds to &ldquo;Add bi-directional marks&rdquo; option in the MS Word File Conversion dialog when you export to a Plain Text format. Note that it appears in dialog only if any of the Arabic or Hebrew editing languages are added in MS Word.<\/p>\n<p>The following code example shows how to use <code>TxtSaveOptions.AddBidiMarks<\/code> property.\u00a0The default value of this property is\u00a0<em>true<\/em>:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-AddBidiMarks.java\"><\/script>\n\n<h2 id=\"recognize-list-items-during-loading-txt\">Recognize List Items During Loading TXT<\/h2>\n<p>Aspose.Words can import list item of a text file as list numbers or plain text in its document object model. The <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtloadoptions\/#getDetectNumberingWithWhitespaces\">DetectNumberingWithWhitespaces<\/a> property allows to specify how numbered list items are recognized when a document is imported from plain text format:<\/p>\n<ul>\n<li>If this option is set to\u00a0<em>true<\/em>, whitespaces are also used as list number delimiters: list recognition algorithm for Arabic style numbering (1., 1.1.2.) uses both whitespaces and dot (&quot;.&quot;) symbols.<\/li>\n<li>If this option is set to\u00a0<em>false<\/em>, the lists recognition algorithm detects list paragraphs, when list numbers ends with either dot, right bracket or bullet symbols (such as &ldquo;\u2022&rdquo;, &ldquo;*&rdquo;, &ldquo;-&rdquo; or &ldquo;o&rdquo;).<\/li>\n<\/ul>\n<p>The following code example shows how to use this property:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-DetectNumberingWithWhitespaces.java\"><\/script>\n\n<h2 id=\"handle-leading-and-trailing-spaces-during-loading-txt\">Handle Leading and Trailing Spaces during Loading TXT<\/h2>\n<p>You can control the way of handling leading and trailing spaces during loading TXT files. The leading spaces could be trimmed, preserved or converted to indent and trailing spaces could be trimmed or preserved.<\/p>\n<p>The code example given below shows how to trim leading and trailing spaces while importing the TXT file:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-HandleSpacesOptions.java\"><\/script>\n\n<h2 id=\"detect-document-text-direction\">Detect Document Text Direction<\/h2>\n<p>Aspose.Words provides\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtloadoptions\/#getDocumentDirection\">DocumentDirection<\/a>\u00a0property in <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtloadoptions\/\">TxtLoadOptions<\/a> class to detect the text direction (RTL \/ LTR) in the document. This property sets or gets document text directions provided in\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/documentdirection\/\">DocumentDirection<\/a>\u00a0enumeration.\u00a0The default value is left to right.<\/p>\n<p>The following code example shows how to detect the text direction of the document while importing the TXT file:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-DocumentTextDirection.java\"><\/script>\n\n<h2 id=\"export-header-and-footer-in-output-txt-file\">Export Header and Footer in Output TXT File<\/h2>\n<p>If you want to export the header and footer in the output TXT document, you can use the <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtsaveoptions\/#getExportHeadersFootersMode\">ExportHeadersFootersMode<\/a> property. This property specifies the way headers and footers are exported to the plain text format.<\/p>\n<p>The following code example shows how to export headers and footers to plain text format:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-ExportHeadersFootersMode.java\"><\/script>\n\n<h2 id=\"export-list-indentation-in-output-txt\">Export List Indentation in Output TXT<\/h2>\n<p>Aspose.Words introduced <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtlistindentation\/\">TxtListIndentation<\/a> class that allows specifying how list levels are indented while exporting to a plain text format. While working with <a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtsaveoptions\/\">TxtSaveOption<\/a>, the\u00a0<a href=\"https:\/\/reference.aspose.com\/words\/java\/com.aspose.words\/txtsaveoptions\/#getListIndentation\">ListIndentation<\/a> property is provided to specify the character to be\u00a0used for indenting list levels and\u00a0count specifying\u00a0how many characters to use as indentation per one list level.<\/p>\n<p>The default value for character property is\u00a0&lsquo;\\0&rsquo; indicating that there is no indentation. For count property, the default value is 0 which means no indentation.<\/p>\n<h3 id=\"using-tab-character\">Using Tab Character<\/h3>\n<p>The following code example shows how to export list levels using tab characters:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-useTabCharacterPerLevelForListIndentation.java\"><\/script>\n\n<h3 id=\"using-space-character\">Using Space Character<\/h3>\n<p>The following code example shows how to export list levels using space characters:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-useSpaceCharacterPerLevelForListIndentation.java\"><\/script>\n\n<h3 id=\"using-default-indentation\">Using Default Indentation<\/h3>\n<p>The following code example shows how to export list levels using default indentation:<\/p>\n<script type=\"application\/javascript\" src=\"https:\/\/gist.github.com\/aspose-words-gists\/827e71ccc0b8516a3cfe247b86ce6d4e.js?file=Examples-src-main-java-com-aspose-words-examples-loading_saving-WorkingWithTxt-defaultLevelForListIndentation.java\"><\/script>\n\n<hr>\n<h2 id=\"faq\">FAQ<\/h2>\n<ol>\n<li>\n<p><strong>Q:<\/strong> How can I include headers and footers when saving a document as plain text?<br>\n<strong>A:<\/strong> Set the <code>ExportHeadersFootersMode<\/code> property of <code>TxtSaveOptions<\/code> to the desired mode (e.g., <code>ExportHeadersFootersMode.All<\/code>). This tells Aspose.Words to write header and footer text into the resulting TXT file.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How do I control list indentation in the exported TXT file?<br>\n<strong>A:<\/strong> Use the <code>ListIndentation<\/code> property of <code>TxtSaveOptions<\/code>. You can specify a character (tab, space, or custom) and the number of such characters per list level to achieve the required indentation.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I preserve leading and trailing spaces when loading a TXT file?<br>\n<strong>A:<\/strong> Configure <code>TxtLoadOptions<\/code> with the appropriate <code>LeadingSpaces<\/code> and <code>TrailingSpaces<\/code> settings (e.g., <code>LeadingSpaces.Preserve<\/code> and <code>TrailingSpaces.Preserve<\/code>). This prevents Aspose.Words from trimming or converting those spaces.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> What does the <code>AddBidiMarks<\/code> option do and when should I use it?<br>\n<strong>A:<\/strong> When <code>AddBidiMarks<\/code> is true, Aspose.Words inserts a RIGHT\u2011TO\u2011LEFT MARK (U+200F) before each bi\u2011directional run in the exported text. Enable it when the document contains Arabic or Hebrew text and you need the correct visual order in plain\u2011text files.<\/p>\n<\/li>\n<li>\n<p><strong>Q:<\/strong> How can I detect the text direction (RTL\/LTR) of a TXT document during import?<br>\n<strong>A:<\/strong> Use the <code>DocumentDirection<\/code> property of <code>TxtLoadOptions<\/code>. After loading, the property reflects the detected direction, allowing you to handle right\u2011to\u2011left or left\u2011to\u2011right content appropriately.<\/p>\n<\/li>\n<\/ol>\n\n      "}]}}