Watermark Entire PDF File without Looping through Pages using C# .NET

Current sample ASPOSE code block to apply water mark on PDF is running with loop page by page, which is time consuming and may yield to performance.

Plz suggest, if you have any .Net watermark functions which can apply on entire document, rather than looping through the page.


This Topic is created by awais.hafeez using Email to Topic tool.

@subramanyam.gvsrb

We are afraid that watermark is basically page level operation so you need to add it page by page only. It can not be set on Document level at once.

Hi,

Our previous vendor use to support at Document level and response is very quick though pdf file has 500 pages or more.

But our current vendor is not supporting this and we are running out of memory performance issues. This is one of the reason for us to look for a new vendor.

Can you plz provide full code block including releasing memory to apply watermark diagonally on pdf and tif on entire document? We will do a load test.

@subramanyam.gvsrb

Please try the following code on your end where you can modify and adjust some properties as per your requirements.

//load a PDF document into Aspose.PDF Document object
Aspose.Pdf.Document document = new Aspose.Pdf.Document(@"C:\files\sample.pdf");

//create a text stamp object to setup text watermark
Aspose.Pdf.TextStamp textStamp = new Aspose.Pdf.TextStamp("Text Watermark");

//specify location for the text stamp as text watermark
textStamp.XIndent = 100;
textStamp.YIndent = 100;
textStamp.RotateAngle = 45;

//set text attributes of the text watermark
textStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Calibri");
textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;
textStamp.TextState.FontSize = 24.0F;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Red;
textStamp.TextState.BackgroundColor = Aspose.Pdf.Color.Silver;

foreach (Page page in document.Pages)
{                
    page.AddStamp(textStamp);
    // Clears cached data
    page.FreeMemory();
}
//save the output file having the text watermark on it
document.Save(@"C:\files\output.pdf");
document.FreeMemory();