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

งานส่วนใหญ่ที่คุณต้องดำเนินการกับ 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-Python-via-.NET
doc = aw.Document(docs_base.my_dir + "Document.doc")
doc.save(docs_base.artifacts_dir + "BaseConversions.doc_to_docx.docx")

บันทึกเอกสารลงในสตรีม

ส่งออบเจ็กต์สตรีมไปยังวิธี save จำเป็นต้องระบุรูปแบบการบันทึกอย่างชัดเจนเมื่อบันทึกลงในสตรีม

ตัวอย่างโค้ดต่อไปนี้แสดงวิธีการโหลดและบันทึกเอกสารลงในสตรีม:

# For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Python-via-.NET
# Read only access is enough for Aspose.words to load a document.
stream = io.FileIO(docs_base.my_dir + "Document.docx")
doc = aw.Document(stream)
# You can close the stream now, it is no longer needed because the document is in memory.
stream.close()
# ... do something with the document.
# Convert the document to a different format and save to stream.
dstStream = io.FileIO(docs_base.artifacts_dir + "BaseConversions.docx_to_rtf.rtf", "wb")
doc.save(dstStream, aw.SaveFormat.RTF)
dstStream.close()

คุณสามารถดาวน์โหลดไฟล์เทมเพลตของตัวอย่างนี้ได้จาก 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-Python-via-.NET
doc = aw.Document(docs_base.my_dir + "Rendering.docx")
saveOptions = aw.saving.PclSaveOptions()
saveOptions.save_format = aw.SaveFormat.PCL
saveOptions.rasterize_transformed_elements = False
doc.save(docs_base.artifacts_dir + "WorkingWithPclSaveOptions.rasterize_transformed_elements.pcl", saveOptions)