文書を保存する

Aspose.Wordsで実行する必要があるタスクのほとんどには、文書の保存が含まれます。 ドキュメントAspose.Wordsを保存するには、DocumentクラスのSaveメソッドを提供します。 文書はAspose.Wordsでサポートされている任意の保存形式で保存できます。 サポートされているすべての保存形式の一覧については、SaveFormat列挙を参照してください。

ファイル {#save-a-document-to-a-file}に保存する

ファイル名を指定してSaveメソッドを使用するだけです。 Aspose.Wordsは、指定したファイル拡張子から保存形式を決定します。

次のコード例は、ドキュメントを読み込んでファイルに保存する方法を示しています:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(LoadAndSave.class);
Document doc = new Document(dataDir+ "Test File (doc).doc");
// Save the finished document to disk.
doc.save(dataDir + "Test File (doc)_out.doc", SaveFormat.PNG);

ストリーム {#save-a-document-to-a-stream}に保存する

StreamオブジェクトをSaveメソッドに渡します。 ストリームに保存するときは、保存形式を明示的に指定する必要があります。

ドキュメントを読み込んでストリームに保存する方法を次のコード例に示します:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(LoadAndSaveToStream.class);
String inputFile = "Test File (doc).doc";
String outputFile = "output.png";
InputStream in = new FileInputStream(dataDir + inputFile);
OutputStream out = new FileOutputStream(dataDir + outputFile);
Document doc = new Document(in);
// Save the finished document to disk.
doc.save(out, SaveFormat.PNG);

この例のテンプレートファイルは、次の場所からダウンロードできます Aspose.Words GitHub.

PCL {#save-a-document-to-pcl}に保存

Aspose.Wordsは、PCL(プリンタコマンド言語)への文書の保存をサポートします。 Aspose.Wordsは、文書をPCL6(PCL6EnhancedまたはPCLXL)形式で保存できます。 PclSaveOptionsクラスは、ドキュメントをPCL形式で保存するときに追加のオプションを指定するために使用できます。

次のコード例は、保存オプションを使用して文書をPCLに保存する方法を示しています:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// The path to the documents directory.
String dataDir = Utils.getDataDir(ConvertDocumentToPCL.class);
// Load the document from disk.
Document doc = new Document(dataDir + "Document.doc");
PclSaveOptions saveOptions = new PclSaveOptions();
saveOptions.setSaveFormat(SaveFormat.PCL);
saveOptions.setRasterizeTransformedElements(false);
// Export the document as an PCL file.
doc.save(dataDir + "Document.PclConversion_out.pcl", saveOptions);