Text section for Redaction

Hi… I am looking for an updated example of how to retrieve the rectangle of the selected text, so I can redaction it. I am looking to do this in C# winforms.

Every example I have found in this group is a few years old and not workable.

Any guidance is greatly appreciated… thanks

Ok… I got it to work using the rectangle select tool, but if I use that tool to select more than one line, it only redacts the first line and keeps the other lines highlighted.

The following code will redact all text currently selected in the document.

You put this code into something like SetSmoothImages function in PDFViewForm.cs in the PDFViewTest sample project. Then you can highlight text, and then in the toolbar pick the Options->Smooth Images option to redact.

ArrayList rarr = new ArrayList();
int itr = Current_View.GetSelectionBeginPage();
int end = Current_View.GetSelectionEndPage();
for (; itr <= end; ++itr)
PDFViewWPF.Selection selection = Current_View.GetSelection(itr);
double[] quads = selection.GetQuads();
int sz = quads.Length / 8; //each quad has eight numbers (x0, y0), ... (x3, y3)
if (sz == 0) continue;
for(int i = 0; i < sz; ++i)
int offset = 8 * i;
// we just want an axis aligned bounding box.
double[] x_axis = { quads[offset], quads[offset + 2], quads[offset + 4], quads[offset + 6] };
double[] y_axis = { quads[offset + 1], quads[offset + 3], quads[offset + 5], quads[offset + 7] };
double x1 = x_axis.Min();
double y1 = y_axis.Min();
double x2 = x_axis.Max();
double y2 = y_axis.Max();
rarr.Add(new Redactor.Redaction(itr, new pdftron.PDF.Rect(x1, y1, x2, y2), false, ""));
Redactor.Appearance app = new Redactor.Appearance();
app.PositiveOverlayColor = System.Drawing.Color.Red;
app.NegativeOverlayColor = System.Drawing.Color.WhiteSmoke;
Redactor.Redact(Current_View.GetDoc(), rarr, app);

Note, the two types of document locking that occurs. A write lock causes rendering to stop, so we delay until we are ready to redact.

Thank you your time and replying to me, I really appreciate it.

Can I just set “_pdfview.SetImageSmoothing(true);” on form Load to fulfill the Smooth Imagine Requirement?

If so, I added a button to run this code “_pdfview.SetToolMode(PDFViewCtrl.ToolMode.e_highlight_create” to highlight some text

then I ran your code behind another button

but No success, the code is not finding the highlighted text.

Thanks for pointing this out. I corrected the original code, and it worked for me.