iTextSharp - 检查PDF文档属性 - 内容复制,内容复制以获取辅助功能 [英] iTextSharp - Check PDF Document Properties - Content Copying, Content Copying For Accessibility
问题描述
我正在尝试检查要上传的PDF文档是否具有以下文档属性 - 内容复制&内容复制允许/不允许使用iTextSharp PDFReader访问辅助功能。是否有任何属性可以验证此功能。我已粘贴了一个未返回预期结果的示例代码。
I'm trying to check whether PDF document to be uploaded has the following document properties - Content Copying & Content Copying For Accessibility Allowed / Not Allowed using iTextSharp PDFReader. Is there any property to verify this functionality. I have pasted a sample code which is NOT returning the expected result.
使用iTextSharp寻找解决方案
示例代码:
using (PdfReader r = new PdfReader(@"xxx\yyy.pdf"))
{
if (PdfEncryptor.IsScreenReadersAllowed((int)(r.Permissions)))
{
Console.WriteLine("Content Accessibility Enabled");
}
if (PdfEncryptor.IsCopyAllowed((int)(r.Permissions)))
{
Console.WriteLine("Copy Enabled");
}
if (PdfEncryptor.IsAssemblyAllowed((int)(r.Permissions)))
{
Console.WriteLine("Document Assembly Enabled");
}
}
推荐答案
权限
您检查的值仅针对加密的PDF进行初始化。另一方面,您在此处粘贴的示例对话框显示 No Security ,因此您的示例文档未加密。因此,权限
值未设置为任何有意义的值。
The Permissions
value you check is initialized only for encrypted PDFs. The sample dialog you pasted here, on the other hand, shows No Security, so your sample document is not encrypted. Thus, the Permissions
value is not set to any meaningful value.
PDF无法获得任何限制部分加密过程适用于未加密的PDF。因此,您可能希望将测试更新为
None of the restrictions a PDF can get as part of the encryption process apply to non-encrypted PDFs. Thus, you might want to update your tests to
if (PdfEncryptor.IsScreenReadersAllowed((int)(r.Permissions)) || !r.IsEncrypted())
{
Console.WriteLine("Content Accessibility Enabled");
}
if (PdfEncryptor.IsCopyAllowed((int)(r.Permissions)) || !r.IsEncrypted())
{
Console.WriteLine("Copy Enabled");
}
if (PdfEncryptor.IsAssemblyAllowed((int)(r.Permissions)) || !r.IsEncrypted())
{
Console.WriteLine("Document Assembly Enabled");
}
这篇关于iTextSharp - 检查PDF文档属性 - 内容复制,内容复制以获取辅助功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!