Wed Nov 16, 2022 10:32 am
We try with more then one file, both redact and highlight das not work , FindText can't find any word after watermark. If we do only redact or highlight FindText do find those words.
Here is code for watermark and then highlight :
PdfDocument doc = new PdfDocument();
doc.LoadFromFile(@"Path\Onelog 11 Implementation Guide.pdf");
string text = "Test";
foreach (PdfPageBase page in doc.Pages)
{
PdfTilingBrush brush = new PdfTilingBrush(new SizeF(page.Canvas.ClientSize.Width / 2, page.Canvas.ClientSize.Height / 3));
brush.Graphics.SetTransparency(0.3f);
brush.Graphics.Save();
brush.Graphics.TranslateTransform(brush.Size.Width / 2, brush.Size.Height / 2);
brush.Graphics.RotateTransform(-45);
brush.Graphics.DrawString(text, new PdfFont(PdfFontFamily.Helvetica, 24), PdfBrushes.Violet, 0, 0, new PdfStringFormat(PdfTextAlignment.Center));
brush.Graphics.Restore();
brush.Graphics.SetTransparency(1);
page.Canvas.DrawRectangle(brush, new RectangleF(new PointF(0, 0), page.Canvas.ClientSize));
}
List<string> dictionary= new List<string> { "Onelog", "Install" };
foreach (PdfPageBase page in doc.Pages)
{
foreach (string word in dictionary)
{
PdfTextFind[] result = page.FindText(word, TextFindParameter.IgnoreCase).Finds;
foreach (PdfTextFind find in result)
{
find.HighLight(Color.Yellow);
}
}
}
doc.SaveToFile(@"path\Onelog 11 Implementation Guide.pdf");