A “Hello, World!” code is often the first simple example to write uisng “Aspose.Words for Python via .NET”, and it can also be used as a sanity test to ensure the software intended to compile or run source code is correctly installed.
“Aspose.Words for Python via .NET” library gives developers direct access to create, modify, merge, convert, compare Word and Web documents. PDF, DOCX, DOC, RTF, ODT, EPUB, HTML and many other file formats are supported.
Below code snippet follows these steps:
- Create a new empty Document
- Inisialize a DocumentBuilder class
- Insert text to the document start using simple write method
- Open an existing Document from a file. Automatically detects the file format
- Append document “A” to the and of the document “B”
- Save the output as PDF
The following code snippet is a “Hello, World!” program to exhibit working of “Aspose.Words for Python via .NET” API:
# Create a new empty document A docA = aw.Document(); # Inisialize a DocumentBuilder builder = aw.DocumentBuilder(docA); # Insert text to the document A start builder.move_to_document_start(); builder.write("First Hello World paragraph"); # Open an existing document B docB = aw.Document("C:\\Temp\\documentB.docx"); # Add document B to the and of document A, preserving document B formatting docA.append_document(docB, aw.ImportFormatMode.KEEP_SOURCE_FORMATTING); # Save the output as PDF docA.save("C:\\Temp\\output_AB.pdf");