TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Usha Talakanti
NA
31
24.7k
watermark text in all the pdf pages of existing pdf
Jan 7 2016 3:57 AM
how to add watermark (text or image) in existing pdf in c#.I want the watermark in all the pages of the pdf .
I tired by itextsharp but the watermark is displaying in only last page of the pdf.
I want watermark in all pages
public void CreateTemplate(string watermarkText, string targetFileName)
{
var document = new Document();
var pdfWriter = PdfWriter.GetInstance(document, new FileStream(targetFileName, FileMode.Create));
var font = new iTextSharp.text.Font(iTextSharp.text.Font.HELVETICA, 60, iTextSharp.text.Font.NORMAL, iTextSharp.text.Color.LIGHT_GRAY);
document.Open();
ColumnText.ShowTextAligned(pdfWriter.DirectContent, Element.ALIGN_CENTER, new Phrase(watermarkText, font), 300, 400, 45);
document.Close();
}
public void AddTextWatermark(string sourceFilePath, string watermarkTemplatePath, string targetFilePath)
{
var pdfReaderSource = new PdfReader(sourceFilePath);
var pdfStamper = new PdfStamper(pdfReaderSource, new FileStream(targetFilePath, FileMode.Create));
var pdfReaderTemplate = new PdfReader(watermarkTemplatePath);
var page = pdfStamper.GetImportedPage(pdfReaderTemplate, 1);
for (var i = 0; i < pdfReaderSource.NumberOfPages; i++)
{
var content = pdfStamper.GetUnderContent(i + 1);
content.AddTemplate(page, 0, 0);
}
pdfStamper.Close();
pdfReaderTemplate.Close();
}
Reply
Answers (
6
)
Genarate Panel and retrieve Values from Database
Incremental Backup of Database