GroupDocs.Editor Cloud SDK for Java 可轻松与 GroupDocs.Editor Cloud REST API 集成,帮助您在 Java 应用中添加文档编辑功能,无需安装 MS Office 或其他额外应用。使用 Java 编辑器 SDK – 加速对包括 Microsoft Word、Excel 电子表格、演示文稿、TXT、HTML 和 XML 在内的多种支持文档格式的操作。只需将文档加载到任意 WYSIWYG HTML 编辑器中,按需编辑后再准确高效地保存回原始文档格式。
在所有受支持的文件格式上执行最常用的文档编辑操作。GroupDocs.Editor Cloud SDK for Java 构建于 GroupDocs.Editor Cloud REST API 之上,作为一层封装,帮助您管理底层请求和响应,节省宝贵的开发时间。开发者可以专注于在项目中仅编写所需的特定代码。
如果您正在寻找用于在云端标注文件的源代码,请查看 GroupDocs.Editor Cloud SDK for Java at GitHub。
您可以尝试 GroupDocs.Editor Low-Code Java APIs,且没有任何限制。
GroupDocs.Editor Cloud 也提供 Docker 镜像,可用于 self-host 该服务。或者,您可以使用 GroupDocs.Editor High-code APIs 来构建自己的 Java 服务,该工具目前驱动我们的 REST APIs。
//Get your App SID, App Key and Storage Name at https://dashboard.groupdocs.cloud (free registration is required).
Configuration configuration = new Configuration(MyAppSid, MyAppKey);
// Create necessary API instances
EditApi editApi = new EditApi(configuration);
FileApi fileApi = new FileApi(configuration);
// The document already uploaded into the storage.
// Load it into editable state
FileInfo fileInfo = new FileInfo();
fileInfo.setFilePath("WordProcessing/password-protected.docx");
fileInfo.setPassword("password");
WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
loadOptions.setFileInfo(fileInfo);
loadOptions.setOutputPath("output");
LoadResult loadResult = editApi.load(new LoadRequest(loadOptions));
// Download html document
File file = fileApi.downloadFile(new DownloadFileRequest(loadResult.getHtmlPath(), null, null));
// Edit something...
List lines = Files.readAllLines(file.toPath());
List newLines = new ArrayList();
for (String line : lines) {
newLines.add(line.replaceAll("Sample test text", "Hello world"));
}
Files.write(file.toPath(), newLines);
// Upload html back to storage
fileApi.uploadFile(new UploadFileRequest(loadResult.getHtmlPath(), file, Common.MYStorage));
// Save html back to docx
WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions();
saveOptions.setFileInfo(fileInfo);
saveOptions.setOutputPath("output/edited.docx");
saveOptions.setHtmlPath(loadResult.getHtmlPath());
saveOptions.setResourcesPath(loadResult.getResourcesPath());
DocumentResult saveResult = editApi.save(new SaveRequest(saveOptions));
System.out.println("Document edited: " + saveResult.getPath());