1+ using Syncfusion . Drawing ;
2+ using Syncfusion . Pdf ;
3+ using Syncfusion . Pdf . Graphics ;
4+ using Syncfusion . Pdf . Parsing ;
5+ using Syncfusion . Pdf . Redaction ;
6+
7+ // Open the image once; reuse for all redactions.
8+ using FileStream imageStream = new FileStream ( Path . GetFullPath ( @"Data/Image.jpg" ) , FileMode . Open , FileAccess . Read ) ;
9+ PdfBitmap image = new PdfBitmap ( imageStream ) ;
10+
11+ // Load the source PDF.
12+ using ( PdfLoadedDocument document = new PdfLoadedDocument ( Path . GetFullPath ( @"Data/Input.pdf" ) ) )
13+ {
14+ // Find all bounds of the search text across pages.
15+ Dictionary < int , List < RectangleF > > hits ;
16+ document . FindText ( "Fusce" , out hits ) ;
17+ // For each page with matches
18+ foreach ( KeyValuePair < int , List < RectangleF > > kvp in hits )
19+ {
20+ int pageIndex = kvp . Key ;
21+ PdfLoadedPage page = document . Pages [ pageIndex ] as PdfLoadedPage ;
22+ // Replace each matched region by drawing the image in a redaction appearance.
23+ foreach ( RectangleF match in kvp . Value )
24+ {
25+ float pad = 1f ; // Small padding around the text box.
26+ RectangleF box = new RectangleF (
27+ match . X - pad ,
28+ match . Y - pad ,
29+ match . Width + pad * 2 ,
30+ match . Height + pad * 2
31+ ) ;
32+ // Create a transparent redaction over the text area.
33+ PdfRedaction redaction = new PdfRedaction ( box , Color . Transparent ) ;
34+ // Draw the image to fully cover the redaction area (stretched to fit).
35+ RectangleF dest = new RectangleF ( 0 , 0 , box . Width , box . Height ) ;
36+ redaction . Appearance . Graphics . DrawImage ( image , dest ) ;
37+ // Add the redaction to the page.
38+ page . AddRedaction ( redaction ) ;
39+ }
40+ }
41+ // Apply all redactions so the text is removed and image overlays are finalized.
42+ document . Redact ( ) ;
43+ // Save the result.
44+ document . Save ( Path . GetFullPath ( @"Output/Output.pdf" ) ) ;
45+ }
0 commit comments