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();
}









share|improve this question









New contributor




daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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















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();
}









share|improve this question









New contributor




daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • 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













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();
}









share|improve this question









New contributor




daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











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






share|improve this question









New contributor




daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









mkl

51.9k1165142




51.9k1165142






New contributor




daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Nov 15 at 11:46









daoootim

82




82




New contributor




daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






daoootim is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • 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










  • 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












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), check pdfReader.isEncrypted(); if that returns true, the PDF is encrypted using the default user password; otherwise it is not encrypted.






share|improve this answer





















  • thanks for the answer you are a champ
    – daoootim
    yesterday











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






daoootim is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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

























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), check pdfReader.isEncrypted(); if that returns true, the PDF is encrypted using the default user password; otherwise it is not encrypted.






share|improve this answer





















  • thanks for the answer you are a champ
    – daoootim
    yesterday















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), check pdfReader.isEncrypted(); if that returns true, the PDF is encrypted using the default user password; otherwise it is not encrypted.






share|improve this answer





















  • thanks for the answer you are a champ
    – daoootim
    yesterday













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), check pdfReader.isEncrypted(); if that returns true, the PDF is encrypted using the default user password; otherwise it is not encrypted.






share|improve this answer












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), check pdfReader.isEncrypted(); if that returns true, the PDF is encrypted using the default user password; otherwise it is not encrypted.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









mkl

51.9k1165142




51.9k1165142












  • 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




thanks for the answer you are a champ
– daoootim
yesterday










daoootim is a new contributor. Be nice, and check out our Code of Conduct.










 

draft saved


draft discarded


















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.















 


draft saved


draft discarded














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





















































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







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen