我有一个从PDF文档中提取文本的代码,因为有些PDF是密码保护的,我需要一种方法来识别PDF是否受到密码保护。
我正在使用.BitMiracle.Docotic.Pdf库。
目的:-如果我发现PDF作为密码受到保护,那么我将显示一个对话框提示用户输入密码,然后使用该密码打开PDF。
编辑1:解决方案发布为答案
发布于 2016-12-08 05:12:38
我发现库中提供的
IsPasswordProtected()方法,如果当前指定的文件是否受密码保护,它将返回Boolean值。
解决方案:
BitMiracle.Docotic.Pdf.PdfDocument pdfcontent=null;
public static string GetText(string filename)
{
if (PdfDocument.IsPasswordProtected(filename))
{
//method to show dialog for password
pass=getPassword()
using (pdfcontent = new PdfDocument(filename, pass))
{
return pdf.GetTextWithFormatting();
}
}
else
{
using (pdfcontent = new PdfDocument(filename))
{
return pdf.GetTextWithFormatting();
}
}
}https://stackoverflow.com/questions/41016477
复制相似问题