Itextsharp Pdf with password and watermark protected
up vote
1
down vote
favorite
Is there any function in Itextsharp whether pdf has password or watermark.
I have written below code but Contains("Downloaded By") will be dynamic every time.
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();
}
c# asp.net itext
New contributor
add a comment |
up vote
1
down vote
favorite
Is there any function in Itextsharp whether pdf has password or watermark.
I have written below code but Contains("Downloaded By") will be dynamic every time.
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();
}
c# asp.net itext
New contributor
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
– mkl
Nov 15 at 17:52
thanks @mkl. Is there any check whether pdf is Password protected
– daoootim
2 days ago
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Is there any function in Itextsharp whether pdf has password or watermark.
I have written below code but Contains("Downloaded By") will be dynamic every time.
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();
}
c# asp.net itext
New contributor
Is there any function in Itextsharp whether pdf has password or watermark.
I have written below code but Contains("Downloaded By") will be dynamic every time.
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();
}
c# asp.net itext
c# asp.net itext
New contributor
New contributor
edited 2 days ago
mkl
51.9k1165142
51.9k1165142
New contributor
asked Nov 15 at 11:46
daoootim
82
82
New contributor
New contributor
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
– mkl
Nov 15 at 17:52
thanks @mkl. Is there any check whether pdf is Password protected
– daoootim
2 days ago
add a comment |
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
– mkl
Nov 15 at 17:52
thanks @mkl. Is there any check whether pdf is Password protected
– daoootim
2 days ago
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
– mkl
Nov 15 at 17:52
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
– mkl
Nov 15 at 17:52
thanks @mkl. Is there any check whether pdf is Password protected
– daoootim
2 days ago
thanks @mkl. Is there any check whether pdf is Password protected
– daoootim
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Watermarks
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
Passwords
First of all, there are types of passwords in PDFs:
- the user password and
- the owner password.
If a PDF is encrypted and you open it with the owner password, you have full access to the PDF in PDF processors. If you merely open it with the user password, the PDF processor may limit your access according to the PDF specification.
There is a default password value given in the PDF specification. 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.
If the user password is not the default password, you need to enter a password to open the PDF.
Thus,
- if you cannot open a PDF using
new PdfReader(CurrentPath)
, it is encrypted; in particular it is protected with a non-default user password (or a certificate); - if you can open it using
pdfReader = new PdfReader(CurrentPath)
, checkpdfReader.isEncrypted()
; if that returnstrue
, the PDF is encrypted using the default user password; otherwise it is not encrypted.
thanks for the answer you are a champ
– daoootim
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Watermarks
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
Passwords
First of all, there are types of passwords in PDFs:
- the user password and
- the owner password.
If a PDF is encrypted and you open it with the owner password, you have full access to the PDF in PDF processors. If you merely open it with the user password, the PDF processor may limit your access according to the PDF specification.
There is a default password value given in the PDF specification. 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.
If the user password is not the default password, you need to enter a password to open the PDF.
Thus,
- if you cannot open a PDF using
new PdfReader(CurrentPath)
, it is encrypted; in particular it is protected with a non-default user password (or a certificate); - if you can open it using
pdfReader = new PdfReader(CurrentPath)
, checkpdfReader.isEncrypted()
; if that returnstrue
, the PDF is encrypted using the default user password; otherwise it is not encrypted.
thanks for the answer you are a champ
– daoootim
yesterday
add a comment |
up vote
0
down vote
accepted
Watermarks
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
Passwords
First of all, there are types of passwords in PDFs:
- the user password and
- the owner password.
If a PDF is encrypted and you open it with the owner password, you have full access to the PDF in PDF processors. If you merely open it with the user password, the PDF processor may limit your access according to the PDF specification.
There is a default password value given in the PDF specification. 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.
If the user password is not the default password, you need to enter a password to open the PDF.
Thus,
- if you cannot open a PDF using
new PdfReader(CurrentPath)
, it is encrypted; in particular it is protected with a non-default user password (or a certificate); - if you can open it using
pdfReader = new PdfReader(CurrentPath)
, checkpdfReader.isEncrypted()
; if that returnstrue
, the PDF is encrypted using the default user password; otherwise it is not encrypted.
thanks for the answer you are a champ
– daoootim
yesterday
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Watermarks
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
Passwords
First of all, there are types of passwords in PDFs:
- the user password and
- the owner password.
If a PDF is encrypted and you open it with the owner password, you have full access to the PDF in PDF processors. If you merely open it with the user password, the PDF processor may limit your access according to the PDF specification.
There is a default password value given in the PDF specification. 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.
If the user password is not the default password, you need to enter a password to open the PDF.
Thus,
- if you cannot open a PDF using
new PdfReader(CurrentPath)
, it is encrypted; in particular it is protected with a non-default user password (or a certificate); - if you can open it using
pdfReader = new PdfReader(CurrentPath)
, checkpdfReader.isEncrypted()
; if that returnstrue
, the PDF is encrypted using the default user password; otherwise it is not encrypted.
Watermarks
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
Passwords
First of all, there are types of passwords in PDFs:
- the user password and
- the owner password.
If a PDF is encrypted and you open it with the owner password, you have full access to the PDF in PDF processors. If you merely open it with the user password, the PDF processor may limit your access according to the PDF specification.
There is a default password value given in the PDF specification. 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.
If the user password is not the default password, you need to enter a password to open the PDF.
Thus,
- if you cannot open a PDF using
new PdfReader(CurrentPath)
, it is encrypted; in particular it is protected with a non-default user password (or a certificate); - if you can open it using
pdfReader = new PdfReader(CurrentPath)
, checkpdfReader.isEncrypted()
; if that returnstrue
, the PDF is encrypted using the default user password; otherwise it is not encrypted.
answered 2 days ago
mkl
51.9k1165142
51.9k1165142
thanks for the answer you are a champ
– daoootim
yesterday
add a comment |
thanks for the answer you are a champ
– daoootim
yesterday
thanks for the answer you are a champ
– daoootim
yesterday
thanks for the answer you are a champ
– daoootim
yesterday
add a comment |
daoootim is a new contributor. Be nice, and check out our Code of Conduct.
daoootim is a new contributor. Be nice, and check out our Code of Conduct.
daoootim is a new contributor. Be nice, and check out our Code of Conduct.
daoootim is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53318786%2fitextsharp-pdf-with-password-and-watermark-protected%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
A watermark is not necessarily marked as such in a PDF, you won't get a certain check for it.
– mkl
Nov 15 at 17:52
thanks @mkl. Is there any check whether pdf is Password protected
– daoootim
2 days ago