翻譯|使用教程|編輯:胡濤|2022-05-06 14:01:54.920|閱讀 312 次
概述:本文將向您展示如何使用生成的 PDF 文件的加密密碼將 Word 轉換為 PDF,歡迎查閱!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
在 Spire.Doc 的幫助下,開發人員可以使用密碼對 word 進行加密,也可以將 word 文檔轉換為 PDF。本文將向您展示如何使用生成的 PDF 文件的加密密碼將 Word 轉換為 PDF。
確保 .NET版本 5.8.92(或更高版本)的 Spire.Doc 已正確安裝,然后通過以下路徑在下載的 Bin 文件夾中添加 Spire.Doc.dll 作為參考:“..\Spire.Doc\Bin\ NET4.0\Spire.Doc.dll”。
下面是如何直接從 word 到 PDF 轉換創建密碼加密 PDF 的代碼片段。
第 1 步:創建一個新的 Word 文檔并從文件中加載該文檔。
Document document = new Document(); document.LoadFromFile("Sample.docx");
第 2 步:創建 ToPdfParameterList 的實例。
ToPdfParameterList toPdf = new ToPdfParameterList();
第 3 步:設置PDF文檔的打開密碼、權限密碼和用戶權限
toPdf.PdfSecurity.Encrypt("open password","permission password", PdfPermissionsFlags.None, PdfEncryptionKeySize.Key128Bit);
第 4 步:將文檔保存到文件中。
document.SaveToFile("EncryptedPDF.pdf",toPdf);
有效截圖:
完整代碼:
using Spire.Doc; namespace EncryptPDF { class Program { static void Main(string[] args) { Document document = new Document(); document.LoadFromFile("Sample.docx"); ToPdfParameterList toPdf = new ToPdfParameterList(); toPdf.PdfSecurity.Encrypt("open password","permission password", PdfPermissionsFlags.None, PdfEncryptionKeySize.Key128Bit); document.SaveToFile("EncryptedPDF.pdf", toPdf); } } }
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn