Збережіть документ

Більшість завдань, які потрібно виконувати з Aspose.Words задіяти збереження документа. Для збереження документа Aspose.Words забезпечує Save метод Document клас. Документ можна зберігати в будь-якому форматі збереження, що підтримується Aspose.Wordsй Для всіх підтримуваних файлів збереження, див. SaveFormat заохочення.

Збережіть файл

Просто використовуйте 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 метод. Необхідно вказати формат збереження прямо при збереженні потоку.

Приклад коду показує, як завантажити і зберегти документ на потік:

// 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

Aspose.Words підтримує збереження документа в PCL (Printer Command Language). Aspose.Words може зберігати документи в форматі PCL 6 (PCL 6 Enhanced або PCL XL) Про нас 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);