Aspose.Words for .NET使用文档教程(2):克隆文档

下载Aspose.Words for .NET最新试用版

克隆文档


如果你需要从单个文档生成数百或数千个文档,只需将文档加载到内存中一次,克隆此文档,然后使用你的数据填充克隆文档。这加速了文档的生成,因为不需要每次都从文件加载和解析文档。克隆是使用Document.Clone方法完成的,该方法执行Document的深层副本并返回克隆文档。下面的代码示例显示了如何深度克隆文档。

// For complete examples and data files, please go to https://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 https://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项目(宏)的数字签名。

保护文档

使用Document.Protect方法保护文档免受更改。此方法通过传递一个Document.Protect来接受ProtectionType参数和可选的密码。下面的代码示例显示了如何保护文档。

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NETDocument doc = new Document(inputFileName);doc.Protect(ProtectionType.AllowOnlyFormFields, "password");

取消保护文档

调用Document.Unprotect即使具有保护密码也会取消保护。下面的代码示例显示了如何取消保护文档。请注意,密码不是必需的。

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NETDocument doc = new Document(inputFileName);doc.Unprotect();

获得保护类型

你可以通过获取Document.ProtectionType属性的值来检索文档保护的类型。下面的代码示例显示了如何获取当前在文档中设置的保护类型。

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NETDocument doc = new Document(inputFileName);ProtectionType protectionType = doc.ProtectionType;

为你推荐:Aspose专题 – Aspose最新资源合集


想要购买正版授权,或者获取更多Aspose.Words相关信息的朋友可以点击” 咨询在线客服“~

在官 下载Aspose.Total速度慢吗nbsp;  ↓↓↓ Aspose.Total最新试用版大放送,更有海量资源!

Aspose新版本

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2019年4月12日
下一篇 2019年4月12日

相关推荐

发表回复

登录后才能评论