ระบุตัวเลือกการบันทึก

เมื่อบันทึกเอกสารคุณสามารถตั้งค่าคุณสมบัติขั้นสูงบางอย่างได้ Aspose.Wordsให้คุณมีSaveOptionsชั้นซึ่งจะช่วยให้การควบคุมที่แม่นยำมากขึ้นของกระบวนการบันทึก มีวิธีการโอเวอร์โหลดของSaveที่ยอมรับวัตถุSaveOptions–มันควรจะเป็นวัตถุของชั้นเรียนที่ได้มาจากชั้นเรียนSaveOptions แต่ละรูปแบบการบันทึกจะมีคลาสที่สอดคล้องกันซึ่งมีตัวเลือกการบันทึกสำหรับรูปแบบการบันทึกนี้ตัวอย่างเช่นมีPdfSaveOptionsเพื่อบันทึกลงในรูปแบบPDFMarkdownSaveOptionsเพื่อบันทึกลงในรูปแบบMarkdownหรือImageSaveOptionsเพื่อบันทึกลงในรูปภาพ บทความนี้แสดงตัวอย่างการทำงานกับคลาสตัวเลือกบางอย่างที่ได้มาจากSaveOptions.

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

// 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(SpecifySaveOption.class);
String fileName = "TestFile RenderShape.docx";
// Load the document.
Document doc = new Document(dataDir + fileName);
// This is the directory we want the exported images to be saved to.
File imagesDir = new File(dataDir, "Images");
// The folder specified needs to exist and should be empty.
if (imagesDir.exists())
imagesDir.delete();
imagesDir.mkdir();
// Set an option to export form fields as plain text, not as HTML input elements.
HtmlSaveOptions options = new HtmlSaveOptions(SaveFormat.HTML);
options.setExportTextInputFormFieldAsText(true);
options.setImagesFolder(imagesDir.getPath());
dataDir = dataDir + Utils.GetOutputFilePath(fileName);
doc.save(dataDir, options);

บทความอธิบายคุณสมบัติบางอย่างที่คุณสามารถควบคุมเมื่อบันทึกเอกสาร.

เข้ารหัสเอกสารด้วยรหัสผ่าน

ใช้คุณสมบัติPasswordเพื่อรับหรือตั้งรหัสผ่านสำหรับเอกสารที่เข้ารหัส ใช้คุณสมบัติPasswordของคลาสที่เกี่ยวข้องเพื่อทำงานกับรูปแบบเอกสารที่เลือก.

ตัวอย่างเช่นเมื่อบันทึกเอกสารไปยังDOCหรือDOTรูปแบบใช้คุณสมบัติPasswordของคลาสของDocSaveOptions.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการตั้งค่ารหัสผ่านเพื่อเข้ารหัสเอกสารโดยใช้วิธีการเข้ารหัสRC4:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
Document doc = new Document(dataDir + "Document.doc");
DocSaveOptions docSaveOptions = new DocSaveOptions();
docSaveOptions.setPassword("password");
dataDir = dataDir + "Document.Password_out.doc";
doc.save(dataDir, docSaveOptions);

เมื่อบันทึกเอกสารไปยังรูปแบบODTใช้คุณสมบัติPasswordของคลาสOdtSaveOptions.

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
Document doc = new Document(dataDir + "encrypted.odt", new com.aspose.words.LoadOptions("password"));
doc.save(dataDir + "out.odt", new OdtSaveOptions("newpassword"));

การเข้ารหัสและการใช้พร็อพเพอร์ตี้Password.

แสดงการแจ้งเตือนความคืบหน้าในการบันทึกเอกสาร

Aspose.Wordsให้ความสามารถในการใช้ProgressCallbackคุณสมบัติที่จะได้รับการแจ้งเตือนเกี่ยวกับความคืบหน้าของก.

ขณะนี้สามารถใช้ได้เมื่อบันทึกไปที่DOCX, FlatOpc, DOCM, DOTM, DOTX, HTML, MHTML, EPUB, XamlFlow, XamlFlowPack, หรือTXTรูปแบบ.

ปรับปรุงเวลาในการสร้างเอกสาร

Aspose.Wordsให้ความสามารถในการใช้CreatedTimeคุณสมบัติที่จะได้รับหรือตั้งวันที่สร้างเอกสารในUTC คุณยังสามารถอัปเดตค่านี้ก่อนที่จะบันทึกโดยใช้ตัวเลือกUpdateCreatedTimeProperty.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการปรับปรุงเวลาในการสร้างเอกสาร:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
// For complete examples and data files, please go to //
// https://github.com/aspose-words/Aspose.Words-for-Java
// Open a document
Document doc = new Document(dataDir + "Rendering.doc");
PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.setUpdateLastPrintedProperty(false);
doc.save(dataDir + "PdfSaveOptions.UpdateIfLastPrinted.pdf", saveOptions);

อัปเดตคุณสมบัติที่บันทึกไว้ล่าสุด

Aspose.Wordsให้ความสามารถในการใช้คุณสมบัติUpdateLastSavedTimePropertyเพื่อรับหรือตั้งค่าการกำหนดว่าคุณสมบัติของLastSavedTimeได้รับการปรับปรุงก่อนที่จะบันทึก.

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

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
Document doc = new Document(dataDir + "Document.doc");
OoxmlSaveOptions ooxmlSaveOptions = new OoxmlSaveOptions();
ooxmlSaveOptions.setUpdateLastSavedTimeProperty(true);
dataDir = dataDir + "UpdateLastSavedTimeProperty_out.docx";
doc.save(dataDir, ooxmlSaveOptions);

บันทึกภาพขาวดำด้วยรูปแบบหนึ่งบิตต่อพิกเซล

เมื่อต้องการควบคุมตัวเลือกการบันทึกภาพจะใช้คลาสImageSaveOptions ตัวอย่างเช่นคุณสามารถใช้คุณสมบัติPixelFormatเพื่อตั้งค่ารูปแบบพิกเซลสำหรับรูปภาพที่สร้างขึ้น โปรดทราบว่ารูปแบบพิกเซลของภาพที่ส่งออกอาจแตกต่างจากค่าที่ตั้งไว้เนื่องจากการทำงานของGDI+.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการบันทึกภาพขาวดำด้วยรูปแบบหนึ่งบิตต่อพิกเซล:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
ImageSaveOptions opt = new ImageSaveOptions(SaveFormat.PNG);
opt.setPageSet(new PageSet(1));
opt.setImageColorMode(ImageColorMode.BLACK_AND_WHITE);
opt.setPixelFormat(ImagePixelFormat.FORMAT_1_BPP_INDEXED);
dataDir = dataDir + "Format1bppIndexed_Out.Png";
doc.save(dataDir, opt);