翻譯|使用教程|編輯:龔雪|2019-05-16 10:29:34.517|閱讀 638 次
概述:本文主要介紹使用Aspose.Words for .NET克隆文檔,保護文檔等。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Aspose.Words無需Microsoft Word也可在任何平臺上滿足Word文檔的一切操作需求。本文將與大家分享如何檢測文件格式和檢查格式兼容性。
【下載Aspose.Words for .NET最新試用版】
如果你需要從單個文檔生成數百或數千個文檔,只需將文檔加載到內存中一次,克隆此文檔,然后使用你的數據填充克隆文檔。 這加速了文檔的生成,因為不需要每次都從文件加載和解析文檔。克隆是使用Document.Clone方法完成的,該方法執行Document的深層副本并返回克隆文檔。下面的代碼示例顯示了如何深度克隆文檔。
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET // The path to the documents directory. string dataDir = RunExamples.GetDataDir_WorkingWithDocument(); // Load the document from disk. Document doc = new Document(dataDir + "TestFile.doc"); Document clone = doc.Clone(); dataDir = dataDir + "TestFile_clone_out.doc"; // Save the document to disk. clone.Save(dataDir);
如果你需要在PDF的窗口標題欄中顯示文檔的標題,PdfSaveOptions.DisplayDocTitle就可以實現此目的。將此屬性的值設置為true,窗口的標題欄中就會顯示文檔的標題。如果此屬性的值為false,則標題欄應顯示包含該文檔的PDF文件的名稱。
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET // The path to the documents directory. string dataDir = RunExamples.GetDataDir_QuickStart(); // Load the document from disk. Document doc = new Document(dataDir + "Template.doc"); PdfSaveOptions saveOptions = new PdfSaveOptions(); saveOptions.DisplayDocTitle = true; dataDir = dataDir + "Template_out.pdf"; // Save the document in PDF format. doc.Save(dataDir, saveOptions);
當文檔受到保護時,用戶只能進行有限的更改,例如添加注釋,修訂或填寫表單。即使文檔受密碼保護,Aspose.Words也不需要密碼來打開,修改或取消保護此文檔。使用Aspose.Words保護文檔時,你可以選擇保留現有密碼或指定新密碼。
如果你需要確保文檔確實受到保護,請考慮對文檔進行數字簽名。Aspose.Words支持檢測DOC,OOXML和ODT文檔的數字簽名。Aspose.Words還保留應用于文檔中包含的VBA項目(宏)的數字簽名。
注意:在Microsoft Word中保護的文檔可以很輕易地被一個沒有密碼的用戶變成不受保護的文檔。當文檔受到保護時,可以在Microsoft Word中打開,保存為RTF或WordprocessingML文檔,然后使用記事本或任何純文本編輯器刪除保護密碼。之后,用戶可以在Microsoft Word中再次打開文檔并另存為不受保護的DOC。
使用Document.Protect方法保護文檔免受更改。此方法通過傳遞一個Document.Protect來接受ProtectionType參數和可選的密碼。下面的代碼示例顯示了如何保護文檔。
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET Document doc = new Document(inputFileName); doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
調用Document.Unprotect即使具有保護密碼也會取消保護。下面的代碼示例顯示了如何取消保護文檔。請注意,密碼不是必需的。
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET Document doc = new Document(inputFileName); doc.Unprotect();
你可以通過獲取Document.ProtectionType屬性的值來檢索文檔保護的類型。下面的代碼示例顯示了如何獲取當前在文檔中設置的保護類型。
// For complete examples and data files, please go to //github.com/aspose-words/Aspose.Words-for-.NET Document doc = new Document(inputFileName); ProtectionType protectionType = doc.ProtectionType;
想要購買正版授權,或者獲取更多Aspose.Words相關信息的朋友可以點擊" "~
在官網下載Aspose.Total速度慢嗎? ↓↓↓ Aspose.Total最新試用版大放送,更有海量資源!
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn