ระบุตัวเลือกการบันทึก
เมื่อบันทึกเอกสารคุณสามารถตั้งค่าคุณสมบัติขั้นสูงบางอย่างได้ 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-C | |
// The path to the documents directories. | |
System::String inputDataDir = GetInputDataDir_LoadingAndSaving(); | |
System::String outputDataDir = GetOutputDataDir_LoadingAndSaving(); | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"TestFile RenderShape.docx"); | |
// This is the directory we want the exported images to be saved to. | |
System::String imagesDir = System::IO::Path::Combine(outputDataDir, u"SpecifySaveOption.Images"); | |
// The folder specified needs to exist and should be empty. | |
if (System::IO::Directory::Exists(imagesDir)) | |
{ | |
System::IO::Directory::Delete(imagesDir, true); | |
} | |
System::IO::Directory::CreateDirectory_(imagesDir); | |
// Set an option to export form fields as plain text, not as HTML input elements. | |
System::SharedPtr<HtmlSaveOptions> options = System::MakeObject<HtmlSaveOptions>(SaveFormat::Html); | |
options->set_ExportTextInputFormFieldAsText(true); | |
options->set_ImagesFolder(imagesDir); | |
System::String outputPath = outputDataDir + u"SpecifySaveOption.html"; | |
doc->Save(outputPath, 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-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.doc"); | |
System::SharedPtr<DocSaveOptions> docSaveOptions = System::MakeObject<DocSaveOptions>(); | |
docSaveOptions->set_Password(u"password"); | |
System::String outputPath = outputDataDir + u"WorkingWithDoc.EncryptDocumentWithPassword.doc"; | |
doc->Save(outputPath, docSaveOptions); |
เมื่อบันทึกเอกสารไปยังรูปแบบODTใช้คุณสมบัติPasswordของคลาสOdtSaveOptions.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการโหลดและบันทึกOpenDocumentเข้ารหัสด้วยรหัสผ่าน:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"encrypted.odt", System::MakeObject<LoadOptions>(u"password")); | |
System::String outputPath = outputDataDir + u"Load_Options.LoadAndSaveEncryptedODT.odt"; | |
doc->Save(outputPath, System::MakeObject<OdtSaveOptions>(u"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-C | |
// Open a document | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"TestFile.docx"); | |
System::SharedPtr<SaveOptions> options = System::MakeObject<PdfSaveOptions>(); | |
options->set_UpdateLastPrintedProperty(false); | |
System::String outputPath = outputDataDir + u"WorkingWithPdfSaveOptions.UpdateIfLastPrinted.pdf"; | |
doc->Save(outputPath, options); |
อัปเดตคุณสมบัติที่บันทึกไว้ล่าสุด
Aspose.Wordsให้ความสามารถในการใช้คุณสมบัติUpdateLastSavedTimePropertyเพื่อรับหรือตั้งค่าการกำหนดว่าคุณสมบัติของLastSavedTimeได้รับการปรับปรุงก่อนที่จะบันทึก.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการตั้งค่าคุณสมบัตินี้และบันทึกเอกสาร:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(inputDataDir + u"Document.doc"); | |
System::SharedPtr<OoxmlSaveOptions> ooxmlSaveOptions = System::MakeObject<OoxmlSaveOptions>(); | |
ooxmlSaveOptions->set_UpdateLastSavedTimeProperty(true); | |
System::String outputPath = outputDataDir + u"WorkingWithOoxml.UpdateLastSavedTimeProperty.docx"; | |
// Save the document to disk. | |
doc->Save(outputPath, ooxmlSaveOptions); |
บันทึกภาพขาวดำด้วยรูปแบบหนึ่งบิตต่อพิกเซล
เมื่อต้องการควบคุมตัวเลือกการบันทึกภาพจะใช้คลาสImageSaveOptions ตัวอย่างเช่นคุณสามารถใช้คุณสมบัติPixelFormatเพื่อตั้งค่ารูปแบบพิกเซลสำหรับรูปภาพที่สร้างขึ้น โปรดทราบว่ารูปแบบพิกเซลของภาพที่ส่งออกอาจแตกต่างจากค่าที่ตั้งไว้เนื่องจากการทำงานของGDI+.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการบันทึกภาพขาวดำด้วยรูปแบบหนึ่งบิตต่อพิกเซล:
For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
System::SharedPtr<ImageSaveOptions> opt = System::MakeObject<ImageSaveOptions>(SaveFormat::Png); | |
auto pageSet = System::MakeObject<PageSet>(System::MakeArray<System::SharedPtr<PageRange>>({System::MakeObject<PageRange>(1,1)})); | |
opt->set_PageSet(pageSet); | |
opt->set_ImageColorMode(ImageColorMode::BlackAndWhite); | |
opt->set_PixelFormat(ImagePixelFormat::Format1bppIndexed); | |
System::String outputPath = outputDataDir + u"ImageColorFilters.SaveImageToOnebitPerPixel.png"; | |
doc->Save(outputPath, opt); |