### Run Aspose.Words for Java Examples with Maven Source: https://docs.aspose.com/words/java/how-to-run-the-examples Execute this command in the repository's root folder to compile and run any example class using Maven. Ensure Maven and a compatible JDK are installed. ```bash mvn clean compile exec:java -Dexec.mainClass=com.aspose.words.examples. ``` -------------------------------- ### Install Setuptools on Ubuntu Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Ensure that setuptools is installed, which is required for building and installing Python packages like JCC. ```bash pip install setuptools ``` -------------------------------- ### Initialize Git and Clone PHP Examples Source: https://docs.aspose.com/words/java/download-and-configure-aspose-words-in-php Initializes a Git repository and clones the Aspose.Words Java for PHP examples into the webapps/JavaBridge directory. This fetches the example source code. ```bash $ git init $ git clone [https://github.com/aspose-words/Aspose.Words-for-Java/tree/master/Plugins/Aspose_Words_Java_for_PHP] ``` -------------------------------- ### Import Aspose.Words Code Examples Source: https://docs.aspose.com/words/java/installing-and-using-aspose-words-java-for-eclipse-maven Utilize the Aspose.Words Code Example wizard in Eclipse to import sample Java code into your project. This wizard copies example files and necessary resources to your workspace. ```java package com.aspose.words.examples.document; import org.testng.annotations.Test; import com.aspose.words.Document; public class DocumentExamples { @Test public void createNewDocument() throws Exception { // The path to the document directory. // The output document will remain in the same directory. String dataDir = "Test/DataDir/"; Document doc = new Document(); doc.save(dataDir + "HelloWorld.doc"); } } ``` -------------------------------- ### Install JCC on Ubuntu Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Install the JCC package on Ubuntu using the prefix option to specify the installation directory. ```bash python setup.py install --prefix=~/.local ``` -------------------------------- ### Install Pip Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Installs pip, the package installer for Python, if it is not already present. Pip is necessary for installing Python packages. ```bash Copy> sudo apt install python-pip ``` -------------------------------- ### Aspose.Words Code Example Wizard Source: https://docs.aspose.com/words/java/installing-and-using-aspose-words-for-netbeans-maven Import Aspose.Words for Java API code examples into your NetBeans project using this wizard. It copies selected example Java files and necessary resources to your project structure. ```java package com.aspose.words.examples.document; public class LoadAndSave { public static void main(String[] args) throws Exception { // The path to the documents directory. String dataDir = "Documents/"; // ExStart:LoadAndSave // Load the document from disk. com.aspose.words.Document doc = new com.aspose.words.Document(dataDir + "Document.doc"); // Save the document in the old format. doc.save(dataDir + "Document Out.doc"); // ExEnd:LoadAndSave } } ``` -------------------------------- ### Install Aspose.Words Java for Ruby Gem Directly Source: https://docs.aspose.com/words/java/aspose-words-java-for-ruby Run this command to install the Aspose.Words Java for Ruby gem directly. ```bash $ gem install aspose-wordsjavaforruby ``` -------------------------------- ### Hello, World! Example in Java Source: https://docs.aspose.com/words/java/hello-world This snippet demonstrates creating a new document, adding text, appending another document, and saving the result as a PDF using Aspose.Words for Java. It's a foundational example for new users. ```java // For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git. Document docA = new Document(); DocumentBuilder builder = new DocumentBuilder(docA); // Insert text to the document start. builder.moveToDocumentStart(); builder.write("First Hello World paragraph"); Document docB = new Document(getMyDir() + "Document.docx"); // Add document B to the and of document A, preserving document B formatting. docA.appendDocument(docB, ImportFormatMode.KEEP_SOURCE_FORMATTING); docA.save(getArtifactsDir() + "HelloWorld.SimpleHelloWorld.pdf"); ``` -------------------------------- ### Copy Aspose.Words Code Examples Source: https://docs.aspose.com/words/java/aspose-words-java-for-netbeans-maven Utilize the 'Aspose.Words Code Example' wizard in NetBeans IDE to copy downloaded code examples into your project. Select examples from a tree format, and the wizard will copy them to the 'com.aspose.words.examples' package and necessary resources to 'src/main/resources'. The wizard also checks for updates to code examples. ```java com.aspose.words.examples.Document.HelloWorld.run(); ``` -------------------------------- ### Install JAI on Linux (64-bit) Source: https://docs.aspose.com/words/java/system-requirements Commands to download, extract, and install JAI 1.1.3 on a 64-bit Linux system, including moving JAR and SO files to the appropriate JDK/JRE directories. ```bash Copy$ cd /tmp $ wget https://download.java.net/media/jai/builds/release/1_1_3/jai-1_1_3-lib-linux-amd64.tar.gz && \ gunzip -c jai-1_1_3-lib-linux-amd64.tar.gz | tar xf - && \ mv /tmp/jai-1_1_3/lib/*.jar $JAVA_HOME/jre/lib/ext/ && \ mv /tmp/jai-1_1_3/lib/*.so $JAVA_HOME/jre/lib/amd64/ && \ rm /tmp/jai-1_1_3-lib-linux-amd64.tar.gz && \ rm -r /tmp/jai-1_1_3 ``` -------------------------------- ### Install Aspose.Words Java for Ruby Gem using Bundler Source: https://docs.aspose.com/words/java/aspose-words-java-for-ruby Execute this command after adding the gem to your Gemfile to install it using Bundler. ```bash $ bundle ``` -------------------------------- ### Install JAI Image I/O on Linux (64-bit) Source: https://docs.aspose.com/words/java/system-requirements Commands to download, extract, and install JAI Image I/O 1.1 on a 64-bit Linux system, including moving JAR and SO files to the appropriate JDK/JRE directories. ```bash Copy$ cd /tmp $ wget https://download.java.net/media/jai-imageio/builds/release/1.1/jai_imageio-1_1-lib-linux-amd64.tar.gz && \ gunzip -c jai_imageio-1_1-lib-linux-amd64.tar.gz | tar xf - && \ mv /tmp/jai_imageio-1_1/lib/*.jar $JAVA_HOME/jre/lib/ext/ && \ mv /tmp/jai_imageio-1_1/lib/*.so $JAVA_HOME/jre/lib/amd64/ && \ rm /tmp/jai_imageio-1_1-lib-linux-amd64.tar.gz && \ rm -r /tmp/jai_imageio-1_1 ``` -------------------------------- ### Check Python Installation Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Verifies if Python is installed on the system and displays its version. This is a prerequisite for using Aspose.Words for Python. ```bash Copy> python Python 2.7.13 (default, Jan 19 2017, 14:48:08) [GCC 6.3.0 20170118] on linux2 Type "help", "copyright", "credits" or "license" for more information. ``` -------------------------------- ### Install Wheel Package Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Install the wheel package, which is a build system for Python packages. ```bash pip install wheel ``` -------------------------------- ### Build a Multilevel List Source: https://docs.aspose.com/words/java/using-documentbuilder-to-modify-a-document This example demonstrates how to construct a multilevel list using DocumentBuilder. ```java DocumentBuilder builder = new DocumentBuilder(); // Create the first level list builder.getListFormat().applyBulletDefault(); builder.writeln("Item 1"); builder.writeln("Item 2"); // Increase the list level to create a second level list builder.getListFormat().listIndent(); builder.writeln("Subitem 2.1"); builder.writeln("Subitem 2.2"); // Increase the list level again to create a third level list builder.getListFormat().listIndent(); builder.writeln("Subitem 2.2.1"); // Decrease the list level builder.getListFormat().listOutdent(); builder.writeln("Subitem 2.3"); // Remove list formatting builder.getListFormat().removeNumbers(); builder.writeln("This is no longer a list item."); ``` -------------------------------- ### Install Java Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Installs Oracle Java 8 on Ubuntu. Java is a required dependency for Aspose.Words for Python via Java. ```bash Copy> sudo add-apt-repository ppa:webupd8team/java > sudo apt-get update > sudo apt-get install oracle-java8-installer ``` -------------------------------- ### JSON Data Example (Root Object) Source: https://docs.aspose.com/words/java/accessing-json-data This is an example of a JSON object that can be loaded as a data source. ```json { Name: "John Doe", Age: 30, Birth: "1989-04-01 4:00:00 pm", Child: [ "Ann Doe", "Charles Doe" ] } ``` -------------------------------- ### Install Aspose.Words Python Package on Windows Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Install the generated Aspose.Words Python package (.whl file) on Windows using pip. ```bash pip install .\aspose_words-17.8-cp27-none-win_amd64.whl ``` -------------------------------- ### Install Tomcat Server on Linux Source: https://docs.aspose.com/words/java/download-and-configure-aspose-words-in-php Installs the Tomcat server on a Linux system. This is a prerequisite for running Java applications that will be accessed via PHP. ```bash sudo apt-get install tomcat8 ``` -------------------------------- ### IF Field Examples Source: https://docs.aspose.com/words/java/introduction-to-fields Provides examples of IF field calculations, including comparisons of numbers, strings, and wildcard matching. ```plaintext IF 3 > 5.7^4+MAX(4,3) True False ``` ```plaintext IF "abcd" > "abc" True False ``` ```plaintext IF "?ab*" = "1abdsg" True False ``` ```plaintext IF 4 = "2*2" True False ``` -------------------------------- ### Install Aspose.Words for Python via Java Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Installs the Aspose.Words for Python via Java library using a .whl file. Ensure you have the correct version for your Python and system architecture. ```bash Copy> pip install --prefix=~/.local aspose_words-17.8-cp27-none-linux_x86_64.whl ``` -------------------------------- ### Install JCC on Windows Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Install the JCC package after building it. This makes JCC available for use in Python projects. ```bash python .\setup.py install ``` -------------------------------- ### Install FastCGI Source: https://docs.aspose.com/words/java/download-and-configure-aspose-words-in-php Installs the FastCGI module for PHP, which may be required for the PHP/Java Bridge to function correctly with Tomcat. ```bash sudo apt-get install php55-cgi ``` -------------------------------- ### Render Shapes in Jython Source: https://docs.aspose.com/words/java/render-shapes-in-jython This snippet shows how to render different shapes using Aspose.Words Java for Jython. It's a basic example to get started with shape rendering. ```python # Sample code to render shapes in Jython using Aspose.Words Java # Note: Actual code implementation would go here. # This is a placeholder as the source did not contain a concrete code example. print "Shape rendering code would be here." ``` -------------------------------- ### Get Font Line Spacing Source: https://docs.aspose.com/words/java/working-with-fonts This example shows how to retrieve the line spacing of a font using the LineSpacing property. ```java double lineSpacing = run.getFont().getLineSpacing(); ``` -------------------------------- ### Define Person Class Source: https://docs.aspose.com/words/java/working-with-table-column-conditional-blocks Defines a simple Person class with methods to get name, age, and representative. This class is used in subsequent examples. ```java public class Person { public String getName() { ... } public int getAge() { ... } public String getRepresentative() { ... } ... } ``` -------------------------------- ### Merge Cells Between Two Specified Cells Source: https://docs.aspose.com/words/java/working-with-merged-cells Demonstrates how to use the mergeCells utility method to merge a specific range of cells within a table. This example loads a document, identifies the start and end cells of the desired range, and then merges them. ```java Document doc = new Document(getMyDir() + "Table with merged cells.docx"); Table table = doc.getFirstSection().getBody().getTables().get(0); // We want to merge the range of cells found inbetween these two cells. Cell cellStartRange = table.getRows().get(0).getCells().get(0); Cell cellEndRange = table.getRows().get(1).getCells().get(1); // Merge all the cells between the two specified cells into one. mergeCells(cellStartRange, cellEndRange); doc.save(getArtifactsDir() + "WorkingWithTables.MergeCellRange.docx"); ``` -------------------------------- ### Initialize Aspose.Words and Create Document Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Demonstrates how to import the Aspose.Words library, initialize the Java Virtual Machine (JVM) with the correct classpath, create a new document, add text using a DocumentBuilder, and save the document. ```python Copy> python import aspose_words aspose_words.initVM(aspose_words.CLASSPATH) d = aspose_words.Document() db = aspose_words.DocumentBuilder(d) db.writeln('Hello world!') d.save('/home/slava/test.docx') ``` -------------------------------- ### Get Display Result of a Field Source: https://docs.aspose.com/words/java/customize-field-properties This example shows how to retrieve the 'display result' or 'fake result' of a field using Aspose.Words for Java. This is useful for fields that do not have a field separator node, as it provides the value that MS Word would calculate on the fly. ```java Document doc = new Document("document.docx"); // Get a specific field (e.g., the first field in the document) Field field = doc.getRange().getFields().get(0); // Get the display result of the field String displayResult = field.getDisplayResult(); System.out.println("Display Result: " + displayResult); ``` -------------------------------- ### Build a Table with a Predefined Style and Options Source: https://docs.aspose.com/words/java/working-with-tablestyle This code example shows how to create a new table, apply a built-in style (MEDIUM_SHADING_1_ACCENT_1), and specify which style options (first column, row bands, first row) should be formatted. It also sets the table to auto-fit its contents. ```java Document doc = new Document(); DocumentBuilder builder = new DocumentBuilder(doc); Table table = builder.startTable(); // We must insert at least one row first before setting any table formatting. builder.insertCell(); // Set the table style used based on the unique style identifier. table.setStyleIdentifier(StyleIdentifier.MEDIUM_SHADING_1_ACCENT_1); // Apply which features should be formatted by the style. table.setStyleOptions(TableStyleOptions.FIRST_COLUMN | TableStyleOptions.ROW_BANDS | TableStyleOptions.FIRST_ROW); table.autoFit(AutoFitBehavior.AUTO_FIT_TO_CONTENTS); builder.writeln("Item"); builder.getCellFormat().setRightPadding(40.0); builder.insertCell(); builder.writeln("Quantity (kg)"); builder.endRow(); builder.insertCell(); builder.writeln("Apples"); builder.insertCell(); builder.writeln("20"); builder.endRow(); builder.insertCell(); builder.writeln("Bananas"); builder.insertCell(); builder.writeln("40"); builder.endRow(); builder.insertCell(); builder.writeln("Carrots"); builder.insertCell(); builder.writeln("50"); builder.endRow(); doc.save(getArtifactsDir() + "WorkingWithTableStylesAndFormatting.BuildTableWithStyle.docx"); ``` -------------------------------- ### Apply License from File Source: https://docs.aspose.com/words/java/licensing This snippet demonstrates how to apply a license by specifying the license file name. The license file is expected to be in the same folder as the Aspose.Words JAR or relative to the executable. It includes basic error handling. ```java License license = new License(); try { license.setLicense("Aspose.Words.lic"); System.out.println("License set successfully."); } catch (Exception e) { System.out.println("\nThere was an error setting the license: " + e.getMessage()); } ``` -------------------------------- ### Create Hello World Document in Jython Source: https://docs.aspose.com/words/java/hello-world-in-jython This snippet shows how to create a simple 'Hello World' document using Aspose.Words Java for Jython. It's a starting point for document generation tasks. ```jython from com.aspose.words import Document, DocumentBuilder doc = Document() db = DocumentBuilder(doc) db.writeln("Hello World!") doc.save("HelloWorld.doc") print "Document created successfully: HelloWorld.doc" ``` -------------------------------- ### PHP Main Function for Table AutoFit Examples Source: https://docs.aspose.com/words/java/working-withtables-in-php This is the main entry point for demonstrating various table auto-fitting methods in Aspose.Words for PHP. ```php public static function main() { // The path to the documents directory. $dataDir = "/usr/local/apache-tomcat-8.0.22/webapps/JavaBridge/Aspose.Words-for-Java_For_PHP/src/programmingwithdocuments/workingwithtables/data/"; // Demonstrate autofitting a table to the window. AutoFitTables::autoFitTableToWindow($dataDir); // Demonstrate autofitting a table to its contents. AutoFitTables::autoFitTableToContents($dataDir); // Demonstrate autofitting a table to fixed column widths. AutoFitTables::autoFitTableToFixedColumnWidths($dataDir); } ``` -------------------------------- ### JSON Data Example (Root Array) Source: https://docs.aspose.com/words/java/accessing-json-data This is an example of a JSON array where each element is an object. ```json [ { Name: "John Doe", Age: 30, Birth: "1989-04-01 4:00:00 pm" }, { Name: "Jane Doe", Age: 27, Birth: "1992-01-31 07:00:00 am" }, { Name: "John Smith", Age: 51, Birth: "1968-03-08 1:00:00 pm" } ] ``` -------------------------------- ### Create HelloWorld Document in Jython Source: https://docs.aspose.com/words/java/download-and-configure-aspose-words-for-jython This snippet demonstrates how to create a simple 'Hello World!' document using Aspose.Words for Java within a Jython environment. Ensure the Aspose.Words for Java JAR is in your 'lib' directory and the data directory is correctly configured. ```python from aspose-words import Settings from com.aspose.words import Document from com.aspose.words import DocumentBuilder class HelloWorld: def __init__(self): dataDir = Settings.dataDir + 'quickstart/' doc = Document() builder = DocumentBuilder(doc) builder.writeln('Hello World!') doc.save(dataDir + 'HelloWorld.docx') print "Document saved." if __name__ == '__main__': HelloWorld() ``` -------------------------------- ### Check JCC Installation on Ubuntu Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Verify that JCC has been installed correctly by checking the specified site-packages directory. ```bash ls /home/_username_/.local/lib/python2.7/site-packages ``` -------------------------------- ### Create a 'Hello World' Document in Ruby Source: https://docs.aspose.com/words/java/hello-world-in-ruby Use this snippet to create a new Word document and add the text 'Hello World!' to it. This requires Aspose.Words for Java and the Rjb gem for Ruby-Java interoperability. ```Ruby data_dir = File.dirname(File.dirname(File.dirname(__FILE__))) + '/data/quickstart/' document = Rjb::import('com.aspose.words.Document').new() builder = Rjb::import('com.aspose.words.DocumentBuilder').new(document) builder.writeln("Hello World!") document.save(data_dir + "HelloWorld.docx") ``` -------------------------------- ### Check JCC Installation on Windows Source: https://docs.aspose.com/words/java/how-to-build-aspose-words-for-python-via-java Verify that the JCC egg file has been installed in the Python site-packages directory. ```bash ls C:\Python27\Lib\site-packages\JCC-3.0-py2.7-win-amd64.egg ``` -------------------------------- ### Setting API Key for AI Model Source: https://docs.aspose.com/words/java/grammar-checking Demonstrates how to create an AI model instance and set an API key, which can be retrieved from environment variables. ```Java String apiKey = System.getenv("API_KEY"); IAiModelText model = (OpenAiModel)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey); ``` -------------------------------- ### Set Page Size and Orientation Source: https://docs.aspose.com/words/java/using-documentbuilder-to-modify-a-document This example shows how to configure page size and orientation for the current section using DocumentBuilder.PageSetup. ```java DocumentBuilder builder = new DocumentBuilder(); // Set page size to A4 builder.getPageSetup().setPageSize(PaperSize.A4); // Set orientation to landscape builder.getPageSetup().setOrientation(Orientation.LANDSCAPE); ``` -------------------------------- ### Start a Numbered List Source: https://docs.aspose.com/words/java/using-documentbuilder-to-modify-a-document Call ListFormat.applyNumberDefault to start a numbered list. This formatting is applied until ListFormat.removeNumbers is called. ```java DocumentBuilder builder = new DocumentBuilder(); builder.getListFormat().applyNumberDefault(); ``` -------------------------------- ### Start a Bulleted List Source: https://docs.aspose.com/words/java/using-documentbuilder-to-modify-a-document Call ListFormat.applyBulletDefault to start a bulleted list. This formatting is applied until ListFormat.removeNumbers is called. ```java DocumentBuilder builder = new DocumentBuilder(); builder.getListFormat().applyBulletDefault(); ``` -------------------------------- ### Apply Compare Method and Process Revisions Source: https://docs.aspose.com/words/java/compare-documents This example demonstrates applying the Compare method to two documents and then iterating through the resulting revisions. It shows how to accept all revisions to make the first document identical to the second. ```Java // For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java // The source document doc1 Document doc1 = new Document(); DocumentBuilder builder = new DocumentBuilder(doc1); builder.writeln("This is the original document."); // The target document doc2 Document doc2 = new Document(); builder = new DocumentBuilder(doc2); builder.writeln("This is the edited document."); // If either document has a revision, an exception will be thrown if (doc1.getRevisions().getCount() == 0 && doc2.getRevisions().getCount() == 0) doc1.compare(doc2, "authorName", new Date()); // If doc1 and doc2 are different, doc1 now has some revisions after the comparison, which can now be viewed and processed if (doc1.getRevisions().getCount() == 2) System.out.println("Documents are equal"); for (Revision r : doc1.getRevisions()) { System.out.println("Revision type: " + r.getRevisionType() + ", on a node of type " + r.getParentNode().getNodeType() + ""); System.out.println("\tChanged text: " + r.getParentNode().getText() + ""); } // All the revisions in doc1 are differences between doc1 and doc2, so accepting them on doc1 transforms doc1 into doc2 doc1.getRevisions().acceptAll(); // doc1, when saved, now resembles doc2 doc1.save(dataDir + "Document.Compare.docx"); doc1 = new Document(dataDir + "Document.Compare.docx"); if (doc1.getRevisions().getCount() == 0) System.out.println("Documents are equal"); if (doc2.getText().trim() == doc1.getText().trim()) System.out.println("Documents are equal"); ``` -------------------------------- ### Apply License from File Source: https://docs.aspose.com/words/java/licensing-android Use this snippet to apply a traditional XML license from a file. Ensure the file path is correct and the license is applied once before any other Aspose.Words classes are used. ```java com.aspose.words.License license = new com.aspose.words.License(); java.io.FileInputStream stream = new java.io.FileInputStream("/mnt/sdcard/MyLicense.lic"); license.setLicense(stream); ``` -------------------------------- ### Create VBA Project and Module Source: https://docs.aspose.com/words/java/working-with-vba-macros Demonstrates how to create a new VBA project and a VBA module with basic properties like Name and Type using the Aspose.Words API. ```java VbaProject vbaProject = new VbaProject(); VbaModule module = vbaProject.getModules().add("MyModule", VbaModuleType.PROCEDURAL_MODULE); module.setName("MyModule"); document.getVbaProject().set(vbaProject); ``` -------------------------------- ### Integrate Self-hosted LLM (OpenAI) Source: https://docs.aspose.com/words/java/supported-ai-models Shows how to create and use a self-hosted AI model based on OpenAI's generative language model for document translation. Ensure the API_KEY environment variable is set. ```java public void selfHostedModel() throws Exception { Document doc = new Document(getMyDir() + "Big document.docx"); String apiKey = System.getenv("API_KEY"); // Use OpenAI generative language models. AiModel model = new CustomAiModel().withApiKey(apiKey); Document translatedDoc = model.translate(doc, Language.RUSSIAN); translatedDoc.save(getArtifactsDir() + "AI.SelfHostedModel.docx"); } // Custom self-hosted AI model. static class CustomAiModel extends OpenAiModel { protected String getUrl() { return "https://localhost/"; } protected String getName() { return "my-model-24b"; } } ``` -------------------------------- ### Perl Hello World with OLE Automation and Aspose.Words Source: https://docs.aspose.com/words/java/perl-and-aspose-words-for-java Creates a new Aspose.Words Document and DocumentBuilder objects using OLE automation, writes 'Hello world!', and saves the document to 'out.doc'. This method is an alternative to Inline::Java for COM-enabled environments. ```Perl oleobject doc; opeobject builder doc = CREATE oleobject; doc.ConnectToNewObject("Aspose.Words.Document"); builder = CREATE oleobject; builder.ConnectToNewObject("Aspose.Words.DocumentBuilder"); builder.Document = doc; builder.Write("Hello world!"); doc.Save("C:\\Temp\\out.doc"); ``` -------------------------------- ### Template Document Example 3 Source: https://docs.aspose.com/words/java/removing-paragraphs-containing-only-template-syntax-tags This example uses a FOREACH loop with a data table to show how REMOVE_EMPTY_PARAGRAPHS affects list generation. ```plaintext Prefix <> <<[Name]>> <> Suffix ``` -------------------------------- ### Create a Multilevel List Source: https://docs.aspose.com/words/java/working-with-lists Demonstrates how to create a multilevel list by indenting and outdenting paragraphs. List levels are 0-indexed. ```java DocumentBuilder builder = new DocumentBuilder(doc); // Start a numbered list builder.getListFormat().applyNumberDefault(); // First level item builder.writeln("Item 1"); // Increase indent to create a second level item builder.getListFormat().listIndent(); builder.writeln("Item 1.1"); builder.writeln("Item 1.2"); // Decrease indent to return to the first level builder.getListFormat().listOutdent(); builder.writeln("Item 2"); // Increase indent again builder.getListFormat().listIndent(); builder.writeln("Item 2.1"); // Decrease indent twice to return to the first level builder.getListFormat().listOutdent(); builder.getListFormat().listOutdent(); builder.writeln("Item 3"); // Stop list formatting builder.getListFormat().removeNumbers(); ``` -------------------------------- ### XML Data Structure Example Source: https://docs.aspose.com/words/java/accessing-xml-data This is an example of the XML data structure that can be used for document generation. It contains nested elements representing managers and their contracts. ```xml John Smith A Company 1200000 B Ltd. 750000 C & D 350000 Tony Anderson E Corp. 650000 F & Partners 550000 July James G & Co. 350000 H Group 250000 I & Sons 100000 J Ent. 100000 ``` -------------------------------- ### Example Mail Merge Template for an Order Source: https://docs.aspose.com/words/java/linq-reporting-engine-or-mail-merge A typical Mail Merge template includes document content and merge fields. This example shows a basic structure for an order. ```plaintext <> <> <> <> <> <> <> <> <> <> <> ``` -------------------------------- ### Apply License for Aspose.Words for Android via Java Source: https://docs.aspose.com/words/java/aspose-words-for-android-via-java-features Demonstrates how to apply a license to Aspose.Words for Android via Java using the License class. The license file should be accessible, for example, from the assets folder. ```Java License license = new License(); license.setLicense("Aspose.Words.lic"); ``` -------------------------------- ### Common List Template Example Source: https://docs.aspose.com/words/java/appendix-c-typical-templates A common template example that iterates through a collection of managers and displays each manager's name. This is useful for generating simple lists of names. ```plaintext <> <<[getName()]>> <> --- ``` -------------------------------- ### In-Paragraph List Template Example Source: https://docs.aspose.com/words/java/appendix-c-typical-templates Shows how to create an in-paragraph list of client names. This template iterates through a collection of clients and formats their names as a comma-separated string. ```plaintext We provide support for the following clients: <><<[indexOf() != 0 ? ", " : ""]>><<[getName()]>><> ``` -------------------------------- ### Load XML with Multiple Records Source: https://docs.aspose.com/words/java/accessing-xml-data This example shows how to load XML data containing multiple records, treating the root element as a sequence of nested objects. It includes an example of calculating the average of a field. ```xml John Doe 30 1989-04-01 4:00:00 pm Jane Doe 27 1992-01-31 07:00:00 am John Smith 51 1968-03-08 1:00:00 pm ``` ```html <>Name: <<[Name]>>, Age: <<[Age]>>, Date of Birth: <<[Birth]:"dd.MM.yyyy">> <> Average age: <<[persons.average(p => p.Age)]>> ``` ```java Document doc = ... // Loading a template document. XmlDataSource dataSource = ... // Loading XML (without schema). ReportingEngine engine = new ReportingEngine(); engine.buildReport(doc, dataSource, "persons"); ``` -------------------------------- ### Create a Simple Document in Python Source: https://docs.aspose.com/words/java/python-and-aspose-words-for-java This snippet demonstrates how to create a new document, add text, and save it using Aspose.Words for Java via JPype. Ensure Aspose.Words for Java JARs are in the 'lib' folder. ```python import jpype import os.path jarpath = os.path.join(os.path.abspath("."), "lib") jpype.startJVM(jpype.getDefaultJVMPath(), "-Djava.ext.dirs=%s" % jarpath) Document = jpype.JClass("com.aspose.words.Document") DocumentBuilder = jpype.JClass("com.aspose.words.DocumentBuilder") doc = Document() builder = DocumentBuilder(doc) builder.write("Hello world!") doc.save("C:\\Temp\\out.doc") ```