Aspose.Words如何实现转换Word为PDF并设置PDF文件的操作权限

作者:控件中国网   出处:控件中国网   2016-12-07 09:22:25   阅读:89

Aspose.Words是一款综合性的Word文档处理类控件,不仅可以实现Word文档的创建、转换、读取和各种设置,而且所有这些操作都不需要客户或者开发人员电脑上安装任何三方插件或Microsoft Words,在客户使用Word文档时经常需要把Word文件转换为PDF文件,而且对转换后的PDF文件还希望设置一些权限,如设置密码、防止文本复制、不能添加注释等,这篇文档主要介绍如何对转换后的PDF文件设置相关的权限,具体简单的代码如下:
Document doc = new Document(MyDir + "Rendering.doc");
PdfSaveOptions saveOptions = new PdfSaveOptions();
// Create encryption details and set owner password.
PdfEncryptionDetails encryptionDetails = new PdfEncryptionDetails(string.Empty, "password", PdfEncryptionAlgorithm.RC4_128);
// Start by disallowing all permissions.
encryptionDetails.Permissions = PdfPermissions.DisallowAll;
// Extend permissions to allow editing or modifying annotations.
encryptionDetails.Permissions = PdfPermissions.ModifyAnnotations | PdfPermissions.DocumentAssembly;
saveOptions.EncryptionDetails = encryptionDetails;
// Render the document to PDF format with the specified permissions.
doc.Save(MyDir + "Rendering.SpecifyPermissions Out.pdf", saveOptions);
 
具体设置哪些权限,开发人员可以根据需求对encryptionDetails.Permissions属性进行各种组合设置。
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat