2つの簡単な手順を使用して、CGMをOTTに変換できます。まず、 Aspose.PDF for Java を使用してCGMファイルをDOCにレンダリングする必要があります。その後、強力なドキュメント処理API Aspose.Words for Java を使用して、DOCをOTTに変換できます。どちらのAPIも、 Aspose.Total for Java パッケージに含まれています。
CGMをOTTに変換するJavaAPI
変換要件
Maven ベースのプロジェクトから直接Aspose.Total for Javaを簡単に使用できます Aspose.PDF for Java と Aspose.Words for Java あなたのpom.xmlの。
または、 ダウンロード からZIPファイルを取得することもできます。
Document document = new Document("template.cgm"); | |
document.save("DocOutput.doc", SaveFormat.DOC); | |
Document outputDocument = new com.aspose.words.Document("DocOutput.doc"); | |
outputDocument.save("output.ott", SaveFormat.OTT); |
変換要件
CGMをOTTに変換している間、ドキュメントがパスワードで保護されている場合でも、PDF Manipulation API Aspose.PDF for Java を使用してドキュメントを開くことができます。暗号化されたファイルを開くには、 Document オブジェクトを作成し、所有者のパスワードを使用してCGMを開く必要があります。
Document document = new Document("input.cgm", "password"); | |
document.save("Output.doc", SaveFormat.DOC); |
Javaを介してパスワードで保護されたCGMドキュメントを開く
入力ドキュメントをOTTファイル形式で保存するときに、ファイルシステムの代わりにデータベースにドキュメントを保存することもできます。データベースとの間でDocumentオブジェクトの保存と取得を実装する必要がある場合があります。これは、任意のタイプのコンテンツ管理システムを実装する場合に必要になります。 OTTをデータベースに保存するには、多くの場合、ドキュメントをシリアル化してバイト配列を取得する必要があります。これは、 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); | |
} |