C#:使用 Docotic.Pdf 库打开受密码保护的 PDF
C#: Open password protected PDF with Docotic.Pdf library
我有一个从 PDF 文档中提取文本的代码,因此一些 PDF 受密码保护,我需要一种方法来识别 PDF 是否受密码保护
我正在使用。BitMiracle.Docotic.Pdf
图书馆。
Purpose:- If I find the PDF as password protected then I will show a dialog prompt to user to enter password and then open PDF using that password.
编辑 1: 解决方案作为答案发布
I found that IsPasswordProtected()
method provided in library which returns a Boolean
value if current specified file is password protected or not.
解决方案:
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();
}
}
}
我有一个从 PDF 文档中提取文本的代码,因此一些 PDF 受密码保护,我需要一种方法来识别 PDF 是否受密码保护
我正在使用。BitMiracle.Docotic.Pdf
图书馆。
Purpose:- If I find the PDF as password protected then I will show a dialog prompt to user to enter password and then open PDF using that password.
编辑 1: 解决方案作为答案发布
I found that
IsPasswordProtected()
method provided in library which returns aBoolean
value if current specified file is password protected or not.
解决方案:
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();
}
}
}