如何使用C#窗口或Web应用程序保护文件夹中的多个pdf文件? [英] How to protect multiple pdf files in folder using C# windows or web application?

查看:97
本文介绍了如何使用C#窗口或Web应用程序保护文件夹中的多个pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望为所有这些pdf文件设置密码的文件夹中有多个pdf文件.password应该是pdf文件中提供的employee-id。如果任何相关代码有人知道,请提供正确的dll和命名空间。



我的尝试:



请提供正确的代码命名空间和程序集dll文件。

there are number of pdf files in a folder i want to set password to all these pdf files.password should be employee-id provided in that pdf file.if any related code anybody knows please provide it with proper dll and namespaces.

What I have tried:

please provide me proper code with namespace and assembly dll files.

推荐答案

参考此示例并类似地迭代文件夹中的所有文件,并根据您的逻辑分配密码。

refer this example and similarly iterate for all the files in the folder and assign the password based on your logic.
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
using PdfSharp.Pdf.Security;

namespace CP
{ 
    class POCProgram
    { 
        static void Main(string[] args)
        {   
            string path =@"D:\Projects\CPTemp\CPTemp\abc.pdf";
            PdfDocument document = PdfReader.Open(path);
            PdfSecuritySettings securitySettings = document.SecuritySettings; 
            securitySettings.UserPassword = "MyPassword"; 
            document.Save(path);
        } 
    }
}





PDFSharp NuGet [ ^ ],

参考此视频,了解如何使用Visual Studio的软件包管理器控制台安装Nuget软件包 [ ^ ]

请参考目录。 GetFiles方法(字符串)(System.IO) [ ^ ]读取文件夹中的所有文件



Install the Package from PDFSharp NuGet[^],
refer this video to know how to Install Nuget package using Package Manager Console of Visual Studio [^]
refer Directory.GetFiles Method (String) (System.IO)[^] to read all the files from a folder


这篇关于如何使用C#窗口或Web应用程序保护文件夹中的多个pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆