การบันทึกเอกสาร

งานส่วนใหญ่ที่คุณจำเป็นต้องดำเนินการด้วย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(ภาษาคำสั่งเครื่องพิมพ์) Aspose.WordsสามารถบันทึกเอกสารลงในรูปแบบPCL6(PCL6 ปรับปรุงหรือ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);