Add Multiline Watermarks in PDF with different formatting using Aspose.PDF

Hello, I’m trying to add multiline (with different styles) watermark to a PDF is that possible? At the moment the only way I can do this is to create two text stamps.

Thanks,

Paul

@paulg.fileexpert.co

Yes, your understandings are correct. At the moment, you can achieve your requirements by adding two different text stamps inside the PDF. However, we will surely investigate the feasibility to support this feature in the API. Would you please share a sample output PDF having single text stamp with multiple formatting styles. We will log an investigation ticket and share the ID with you.

Apologies for the delay, here is an example of what we would like to achieve.

@paulg.fileexpert.co

We could not find any attached file with your post. Would you please make sure to upload it again.

2 line watermark different fonts.jpg (283.3 KB)

Hopefully it is there now.

@paulg.fileexpert.co

You can use two text stamp instances and set their positions respectively in order to show them on the page as per your requirements. For example, please check the below sample code snippet:

Document doc = new Document();
Page page = doc.Pages.Add();
Aspose.Pdf.TextStamp textStamp = new Aspose.Pdf.TextStamp("Confidential");

// set whether stamp is background
textStamp.Background = false;
textStamp.TextState.Font = FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 30;
textStamp.HorizontalAlignment = HorizontalAlignment.Center;
textStamp.YIndent = (page.GetPageRect(true).Height / 2) - 15;

Aspose.Pdf.TextStamp textStamp2 = new Aspose.Pdf.TextStamp("This is second line");

// set whether stamp is background
textStamp2.Background = false;
textStamp2.TextState.Font = FontRepository.FindFont("Comic Sans MS");
textStamp2.TextState.FontSize = 20;
textStamp2.HorizontalAlignment = HorizontalAlignment.Center;
textStamp2.YIndent = textStamp.YIndent - 30;

page.AddStamp(textStamp);
page.AddStamp(textStamp2);
doc.Save(dataDir + "test.pdf");