Good afternoon.
I’m trying to add a watermark to all the pages in my document.
What I’m doing in the document is:
public void Generate_PDF(byte[] Template, byte[] QrCode)
{
ComponentInfo.SetLicense("....");
using (MemoryStream memoryDocStream = new MemoryStream(ssInvoiceTemplate))
{
try{
DocumentModel document = DocumentModel.Load(memoryDocStream);
//Replaces and stuff
using (MemoryStream qrCodeStream = new MemoryStream(ssQrCode))
{
var picturePlaceholder = document.Content.Find("{QR}").First();
var qrCodeImage = new Picture(document, qrCodeStream, 100, 100);
picturePlaceholder.Set(qrCodeImage.Content);
Section section = document.Sections[0];
Table Line = ConvertToLineTable(LinesData, document); //Helper method to create and stylize Table
document.Sections[0].Blocks.Add(Line);
//add more stuff
var paginator = document.GetPaginator();
int numPages = paginator.Pages.Count;
var destination = new DocumentModel();
for (int i = 0; i < numPages; i++)
{
DocumentModel page = paginator.Pages[i].ConvertToDocument();
Section pageSection = page.Sections[0];
var header = pageSection.HeadersFooters.GetOrAdd(HeaderFooterType.HeaderFirst);
if (i > 0)
{
header.Blocks.Add(
new Paragraph(page, $"Add Stuff: {value}")
{ ParagraphFormat = new ParagraphFormat() { Alignment = HorizontalAlignment.Right } }
);
}
//This works
var imageWatermark = new PictureWatermark(page, new Picture(page, "Canceledd.png", 275,230));
header.Watermark = imageWatermark;
imageWatermark.AutoScale();
imageWatermark.Washout = true;
//This doesnt work
var textWatermark = new TextWatermark(page, "Canceled");
header.Watermark = textWatermark;
textWatermark.SetDiagonal();
textWatermark.Color = Color.Red;
textWatermark.Semitransparent = true;
destination.Import(page, true, true);
}
destination.Save("TestTemplateChanged.pdf");
}
}
}
}
Naturally, I test one watermark at a time and not both at the same time.
any particular reason why the text isn’t working?
alternatively, if you could put the watermark above the content instead of below it, that would be great, because the QR image ends up above the watermark in this case.