TextWatermark watermark = new TextWatermark("This is WaterMark on Attachment", new Font("Arial", 19));
using (PdfDocument doc = Document.Load<PdfDocument>(Utilities.MapSourceFilePath(FilePath)))
{
foreach (PdfAttachment attachment in doc.Attachments)
{
// Check if the attached file is supported by GroupDocs.Watermark
if (attachment.DocumentInfo.FileFormat != FileFormat.Undefined && !attachment.DocumentInfo.IsEncrypted)
{
// Load the attached document
using (Document attachedDocument = attachment.LoadDocument())
{
// Add wateramrk
attachedDocument.AddWatermark(watermark);
// Save changes in the attached file
attachedDocument.Save();
}
}
}
doc.Save();
}