[英]Itextsharp Pdf with password and watermark protected
Is there any function in Itextsharp whether pdf has password or watermark. 在Itextsharp中是否有任何函数是否pdf具有密码或水印。
I have written below code but Contains("Downloaded By") will be dynamic every time. 我写了下面的代码,但Contains(“Downloaded By”)每次都是动态的。
byte[] bytes = Encoding.ASCII.GetBytes(FilePassword);
int page1;
if (FilePassword.Equals(""))
{
PdfReader pdfReader = new PdfReader(CurrentPath, bytes);
countWaterMarkFound = 0;
// Calculate whether watermark exist in the pdf
for (page1 = 1; page1 <= pdfReader.NumberOfPages; page1++)
{
ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy();
string currentPageText = PdfTextExtractor.GetTextFromPage(pdfReader, page1, strategy);
if (currentPageText.Contains("Downloaded By"))
{
countWaterMarkFound++;
// adding new WaterMark here
}
}
pdfReader.Close();
}
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it. 水印不一定在PDF中标记,您不会对其进行特定检查。
First of all, there are types of passwords in PDFs: 首先,PDF中有多种密码:
If a PDF is encrypted and you open it with the owner password , you have full access to the PDF in PDF processors. 如果PDF已加密并且您使用所有者密码打开它,则您可以完全访问PDF处理器中的PDF。 If you merely open it with the user password , the PDF processor may limit your access according to the PDF specification.
如果仅使用用户密码打开它,PDF处理器可能会根据PDF规范限制您的访问。
There is a default password value given in the PDF specification. PDF规范中给出了默认密码值。 If a PDF is encrypted with that password as user password, you can usually open it without entering a password at all or entering the empty string as password.
如果使用该密码将PDF加密为用户密码,则通常可以在不输入密码或输入空字符串作为密码的情况下打开它。
If the user password is not the default password, you need to enter a password to open the PDF. 如果用户密码不是默认密码,则需要输入密码才能打开PDF。
Thus, 从而,
new PdfReader(CurrentPath)
, it is encrypted; new PdfReader(CurrentPath)
打开PDF,则会对其进行加密; in particular it is protected with a non-default user password (or a certificate); pdfReader = new PdfReader(CurrentPath)
, check pdfReader.isEncrypted()
; pdfReader = new PdfReader(CurrentPath)
打开它,请检查pdfReader = new PdfReader(CurrentPath)
pdfReader.isEncrypted()
; if that returns true
, the PDF is encrypted using the default user password; true
,则使用默认用户密码加密PDF; otherwise it is not encrypted.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.