你好,世界!
Contents
[
Hide
]
A"你好,世界!“代码通常是编写uisng"Aspose.WordsforJava"的第一个简单示例,它也可以用作理智测试,以确保正确安装旨在编译或运行源代码的软件。
“Aspose.WordsforJava"库让开发人员可以直接访问创建,修改,合并,转换,比较Word和Web文档。 PDF, DOCX, DOC, RTF, ODT, EPUB, HTML 和许多其他文件格式是 支持.
Below code代码段遵循以下步骤:
- 创建一个新的空Document
- 初始化DocumentBuilder类
- 插入文本到文档开始使用简单的Write方法
- 从文件中打开现有的Document。 自动检测文件格式
- Append文件"A"到文件"B"的和
- Save输出为PDF
下面的代码片段是一个"你好,世界!“example to exhibit working of"Aspose.WordsforJava"API:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |