Strikethrough text in PDF files using WPF PDF Viewer

1 Feb 20227 minutes to read

The WPF PDF Viewer allows the user to strikethrough text in PDF files and provides options to edit or remove the existing strikethrough. The strikethrough inclusion mode can be enabled via the toolbar UI or the API. Once the strikethrough inclusion mode is activated, you can strikethrough the required text by selecting it. To select the text, hold down the left mouse button and drag the mouse pointer over the text.

To enable the mode from UI, click the below icon in the default toolbar of PdfViewerControl.

Strikethrough icon in the WPF PDF Viewer toolbar

NOTE

From version 19.4.0.48, we have updated our default text extraction engine to PDFium for extracting text information from PDF documents. Based on the text information, we create text markup annotations in the PDF documents. Please refer to the link for more details.

If you are using PdfDocumentView control, or your own toolbar, or if you want enable the mode programmatically, change the AnnotationMode property of PDF Viewer to Strikethrough, as shown in the below code example.

private void EnableStrikethroughInclusionMode()
{
    pdfViewer.AnnotationMode = PdfDocumentView.PdfViewerAnnotationMode.Strikethrough;
}
Private Sub EnableStrikethroughInclusionMode()
    pdfViewer.AnnotationMode = PdfDocumentView.PdfViewerAnnotationMode.Strikethrough
End Sub

The following image shows the strikethrough text in the PDF file.

strikethrough annotation

Change the default color of the strikethrough annotation

NOTE

The left click selection for the strikethrough annotation is supported from 19.3.0.5X version.

The strikethrough color is red by default. However, you can change the default color of the strikethrough programmatically as shown in the following code example.

private void ChangeDefaultStrikethroughColor()
{
    pdfViewer.StrikethroughAnnotationSettings.StrikethroughColor=System.Windows.Media.Colors.Blue;
}
Private Sub ChangeDefaultStrikethroughColor()
    pdfViewer.StrikethroughAnnotationSettings.StrikethroughColor=System.Windows.Media.Colors.Blue
End Sub

Change the default opacity of the strikethrough annotation

The strikethrough opacity value is 1 by default. However, you can change the default opacity of the strikethrough programmatically as shown in the following code example.

private void ChangeDefaultStrikethroughOpacity()
{
    pdfViewer.StrikethroughAnnotationSettings.Opacity = 0.5f;
}
Private Sub ChangeDefaultStrikethroughOpacity()
    pdfViewer.StrikethroughAnnotationSettings.Opacity = 0.5F
End Sub

Change the default author and subject of the strikethrough annotation

You can change the default author and subject of the strikethrough annotation programmatically as shown in the following code example.

private void ChangeDefaultStrikethroughDetails()
{
    pdfviewer.StrikethroughAnnotationSettings.Author = "your name";
    pdfviewer.StrikethroughAnnotationSettings.Subject = "your subject";
}
Private Sub ChangeDefaultStrikethroughDetails()
    pdfviewer.StrikethroughAnnotationSettings.Author = "your name"
    pdfviewer.StrikethroughAnnotationSettings.Subject = "your subject"
End Sub

Working with included/existing strikethrough annotations

Strikethrough annotation supports adding notes along with it, also it allows editing its color and opacity. To use these options, select the included/existing strikethrough annotation and click right using mouse, over the selected annotation, a pop up context menu will appear with the following options,

  • Open Pop-up note
  • Properties
  • Delete

Open Pop-up notes

We can add notes to the strikethrough annotation choosing Open Pop-up note option from the context menu. The following image illustrates the notes added to the selected strikethrough annotation. The added notes will be saved along with the PDF document and if there is any existing notes, it will be displayed in here.

strikethrough annotation

Properties

Selecting properties from the context menu will display the Strikethrough Properties window, which would consist of two tabs

  • Appearance
  • General

Appearance tab

The color and opacity of the strikethrough annotation can be edited using Appearance tab of StrikeOut Properties window.

Editing color of the annotation

The color of the selected strikethrough annotation will be displayed in the color row in the appearance tab. Selecting the Color would displays the color palette control, choosing a color from the color palette and clicking OK will apply the color to the strikethrough annotation.

The following image illustrates how to change the color of the strikethrough annotation included.

strikethrough annotation

The following image illustrates the change in color of the included Strikethrough annotation.

strikethrough annotation

Editing opacity of the annotation

The slider displayed in the Appearance tab will allow us to modify the opacity of the selected strikethrough annotation. You can also modify the opacity of the selected strikethrough annotation by giving numeric value in the opacity text box.

The following image illustrates how to change the opacity of the strikethrough annotation.

strikethrough annotation

The following image illustrates the change in opacity of the included Strikethrough annotation.

strikethrough annotation

General tab

We can add/edit the default Author and Subject of the included strikethrough annotation using General tab of the strikethrough Properties window.

The following image illustrates the change in Author and Subject of the included Strikethrough annotation.

strikethrough annotation

Deleting an annotation

Selecting delete option from the context menu which will be displayed by right click on the selected annotation would delete the respective annotation from the PDF document.

The following image illustrates how to delete the included annotation from the PDF document.

strikethrough annotation

Notification when the strikethrough has changed

The TextMarkupAnnotationChanged event occurs when a strikethrough annotation is added, removed or modified. The TextMarkupAnnotationChangedEventArgs provides the information such as the type of the annotation, the action performed, and the annotation properties.

The following code shows how to wire and handle the event.

//wire the text markup changed event.
pdfViewer.TextMarkupAnnotationChanged += PdfViewer_TextMarkupAnnotationChanged;
private void PdfViewer_TextMarkupAnnotationChanged(object sender, TextMarkupAnnotationChangedEventArgs e)
{
    //Get the action performed on the annotation 
    AnnotationChangedAction action = e.Action;

    //Page index in which this shape annotation was modified 
    int pageNumber = e.PageNumber;

    //Get annotation's new and old bounds (position and size). 
    RectangleF newBounds = e.NewBounds;
    RectangleF oldBounds = e.OldBounds;

    //To identify which type text markup annotation
    TextMarkupAnnotationType type = e.Type;

    TextMarkupAnnotationSettings settings = e.Settings;
    //Annotation's properties which can be modify 
    string author = settings.Author;
    string subject = settings.Subject;
    string Text = settings.Text;
    float opacity = settings.Opacity;
}

NOTE

You can refer to our WPF PDF Viewer feature tour page for its groundbreaking feature representations. You can also explore our WPF PDF Viewer example to know how to render and configure the pdfviewer.