您可以使用两个简单的步骤将 CGM 转换为 FLATOPC。首先,您需要使用 Aspose.PDF for Java 将 CGM 文件渲染为 DOC。之后,通过使用强大的文档处理 API Aspose.Words for Java ,您可以将 DOC 转换为 FLATOPC。这两个 API 都属于 Aspose.Total for Java 包。
Java API 将 CGM 转换为 FLATOPC
Document document = new Document("template.cgm"); | |
document.save("DocOutput.doc", SaveFormat.DOC); | |
Document outputDocument = new com.aspose.words.Document("DocOutput.doc"); | |
//save into related format | |
outputDocument.save("output.docm", SaveFormat.DOCM); |
通过 Java 打开受密码保护的 CGM 文档
在将 CGM 转换为 FLATOPC 时,即使您的文档受密码保护,您仍然可以使用 PDF 操作 API Aspose.PDF for Java 打开它。为了打开加密文件,您需要创建一个 Document 对象并使用所有者的密码打开 CGM。
Document document = new Document("input.cgm", "password"); | |
document.save("Output.doc", SaveFormat.DOC); |
通过 Java 将 FLATOPC 文档保存到数据库
在将输入文档保存为 FLATOPC 文件格式的同时,您还可以将文档保存到数据库而不是文件系统。您可能需要实现在数据库中存储和检索 Document 对象。如果您正在实施任何类型的内容管理系统,这将是必要的。为了将您的 FLATOPC 保存到数据库,通常需要序列化文档以获取字节数组。这可以使用 Aspose.Words for Java API 来完成。获取字节数组后,您可以使用 SQL 语句将其存储在数据库中。
public static void StoreToDatabase(Document doc, Connection mConnection) throws Exception { | |
// create an output stream which uses byte array to save data | |
ByteArrayOutputStream aout = new ByteArrayOutputStream(); | |
// save the document to byte array | |
doc.save(aout, SaveFormat.DOCM); | |
// get the byte array from output steam | |
// the byte array now contains the document | |
byte[] buffer = aout.toByteArray(); | |
// get the filename from the document. | |
String fileName = doc.getOriginalFileName(); | |
String filePath = fileName.replace("\\", "\\\\"); | |
// create the SQL command. | |
String commandString = "INSERT INTO Documents (FileName, FileContent) VALUES('" + filePath + "', '" + buffer + "')"; | |
Statement statement = mConnection.createStatement(); | |
statement.executeUpdate(commandString); | |
} |