您可以使用两个简单的步骤将 PS 转换为 MARKDOWN。首先,您需要使用 Aspose.PDF for Java 将 PS 文件渲染为 DOC。之后,通过使用强大的文档处理 API Aspose.Words for Java ,您可以将 DOC 转换为 MARKDOWN。这两个 API 都属于 Aspose.Total for Java 包。
Java API 将 PS 转换为 MARKDOWN
Document document = new Document("template.ps"); | |
document.save("DocOutput.doc", SaveFormat.DOC); | |
Document outputDocument = new com.aspose.words.Document("DocOutput.doc"); | |
outputDocument.save("output.docm", SaveFormat.DOCM); |
通过 Java 打开受密码保护的 PS 文档
在将 PS 转换为 MARKDOWN 时,即使您的文档受密码保护,您仍然可以使用 PDF 操作 API Aspose.PDF for Java 打开它。为了打开加密文件,您需要创建一个 Document 对象并使用所有者的密码打开 PS。
// open encrypted document
Document document = new Document("input.ps", "password");
// save PS as a DOC
document.save("DocOutput.doc", SaveFormat.DOC);
通过 Java 将 MARKDOWN 文档保存到数据库
在将输入文档保存为 MARKDOWN 文件格式的同时,您还可以将文档保存到数据库而不是文件系统。您可能需要实现在数据库中存储和检索 Document 对象。如果您正在实施任何类型的内容管理系统,这将是必要的。为了将您的 MARKDOWN 保存到数据库,通常需要序列化文档以获取字节数组。这可以使用 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.MARKDOWN);
// 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);
}