Show and Hide Annotations Based on Author in WPF PDF Viewer
Tags: csharp, dotnet, desktop, pdf
Published: 2022-03-04 11:50:55

---
title: Show and Hide Annotations Based on Author in WPF PDF Viewer
published: true
date: 2022-03-04 10:00:05 UTC
tags: csharp, dotnet, desktop, pdf
canonical_url: https://www.syncfusion.com/blogs/post/show-and-hide-annotations-based-on-author-in-wpf-pdf-viewer.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/30nq7wzy4s7wsqw4jxuo.png
---

When multiple users are working on a single PDF file, you might need to hide your comments (annotations) from others, ignore comments already present in the PDF file while you work on it, print only specific comments from the file, and so on.

Syncfusion’s [WPF PDF Viewer](https://www.syncfusion.com/wpf-controls/pdf-viewer "WPF PDF Viewer") control allows you to hide comments in a PDF file without permanently deleting them. This can be done by keeping the comments in the hidden state. You can hide or show annotations using the annotation’s name.

You can hide all the comments at once, rather than hiding each one individually, or hide a specific set of comments. You can also save, print, export, and import annotations in the hidden state.

Let’s see how to hide and show annotations based on the author’s name in your PDF using the WPF PDF Viewer control.

## Getting started

First things first:

1. [Create a new WPF project ](https://docs.microsoft.com/en-us/dotnet/desktop/wpf/getting-started/walkthrough-my-first-wpf-desktop-application "Tutorial: Create a new WPF app with .NET")and install the Syncfusion [WPF PDF Viewer NuGet package](https://www.nuget.org/packages/Syncfusion.PdfViewer.WPF/ "Syncfusion.PdfViewer.WPF NuGet package") in it.
2. Then, include the following code in your XAML page to add the WPF PDF Viewer as a child to the window.
```html
<Window x:Class="PdfViewer.MainWindow"
        xmlns:pdfviewer="clr-namespace:Syncfusion.Windows.PdfViewer;assembly=Syncfusion.PdfViewer.WPF">
   <pdfviewer:PdfViewerControl x:Name="pdfViewer"/>
</Window>
```

## How to hide other authors’ annotations

Let’s see how to hide the annotations of other users. By default, while creating annotations using the WPF PDF Viewer, the [author’s name](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.AnnotationSettings.html#Syncfusion_Windows_PdfViewer_AnnotationSettings_Author "Author property of WPF PDF Viewer") will be set to the username information of the user who is currently logged onto the system.

If the user wants, they can override the default author’s name for the annotations using the [annotation settings](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.AnnotationSettings.html "AnnotationSettings Class of WPF PDF Viewer").

Based on the author’s name, we can easily distinguish and handle (hide or show) their annotations in a PDF document.

### Hiding the annotations

**Step 1:**  First, access the [LoadedDocument](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_LoadedDocument "LoadedDocument property of WPF PDF Viewer") property of the WPF PDF Viewer containing the details of the annotation.

```csharp
//Access the LoadedDocument property.
PdfLoadedDocument pdfLoadedDocument = pdfViewer.LoadedDocument;
```

**Step 2:** Then, iterate through the document pages and access the annotations in the pages.

```csharp
//Iterate through the pages to check for the annotations.
for (int i = 0; i < pdfLoadedDocument.Pages.Count; i++)
{
    //Iterate through the annotations in the page.
    for (int j = 0; j < pdfLoadedDocument.Pages[i].Annotations.Count; j++)
    {
        var annotation = pdfLoadedDocument.Pages[i].Annotations[j];
        //Perform your action.
    }
}
```

**Step 3:** Next, check the author’s name in the annotation data to identify the annotations included by other authors. If the author’s name doesn’t match the name of the current author, obtain the annotation’s name and pass it to the [HideAnnotation](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_HideAnnotation_System_String_ "HideAnnotation method of WPF PDF Viewer") function. This HideAnnotation function hides the annotation based on the annotation’s name, which is passed as a parameter.

For more details, refer to the [Hiding an annotation in WPF PDF Viewer](https://help.syncfusion.com/wpf/pdf-viewer/working-with-annotations/working-with-annotations-programmatically#hide-an-annotation "Hide an annotation in WPF PDF Viewer documentation") documentation.

Refer to the following code example.

```csharp
//Identify whether the annotation was created by the given author.
if (annotation.Author == authorName)
{
    //Hide the annotation.
    pdfViewer.HideAnnotation(annotation.Name);
}
```

**Note:** Before calling the **HideAnnotation** method, make sure that the annotation is set with a unique name to avoid conflicts in identifying the required annotation. Refer to [How to get and set the name of an annotation](https://help.syncfusion.com/wpf/pdf-viewer/working-with-annotations/select-and-modify-annotations#how-to-get-and-set-name-of-an-annotation "How to get and set name of an annotation in WPF PDF Viewer documentation") for more details.

### Show hidden annotation

Similarly, you can show the hidden annotations using the [ShowAnnotation](https://help.syncfusion.com/cr/wpf/Syncfusion.Windows.PdfViewer.PdfViewerControl.html#Syncfusion_Windows_PdfViewer_PdfViewerControl_ShowAnnotation_System_String_ "ShowAnnotation method of WPF PDF Viewer") method.

Refer to the following code example.

```csharp
//Identify whether the annotation was created by the given author.
if (annotation.Author == authorName)
{
    //Show the annotation.
    pdfViewer.ShowAnnotation(annotation.Name);
}
```

![Hide and Show Annotations Based on Author in WPF PDF Viewer](https://www.syncfusion.com/blogs/wp-content/uploads/2022/03/Hide-and-Show-Annotations-Based-on-Author-in-WPF-PDF-Viewer.gif)
_Hide and Show Annotations Based on Author in WPF PDF Viewer_

**Note:** For more details, refer to the [Show annotation in WPF PDF Viewer documentation](https://help.syncfusion.com/wpf/pdf-viewer/working-with-annotations/working-with-annotations-programmatically#show-an-annotation "Show an annotation in WPF PDF Viewer documentation").

## GitHub reference

Also, check out the example to [show and hide annotations based on author in a PDF using the WPF PDF Viewer](https://github.com/SyncfusionExamples/WPF-PDFViewer-Examples/tree/master/Annotations/Hide%20and%20Show%20Annotations/HideComments "show and hide annotations based on author in a PDF using the WPF PDF Viewer GitHub demo").

## Conclusion

Thank you for reading this blog. We have seen how to hide and show annotations based on the author in a PDF file using the Syncfusion [WPF PDF Viewer](https://www.syncfusion.com/wpf-controls/pdf-viewer "WPF PDF Viewer") control. This control allows you to highlight, underline, and strikethrough text; add sticky notes and stamps; draw shapes; and more. Try it in your app and let us know what you think in the comment section below.

Our PDF Viewer is also available in our [Blazor](https://www.syncfusion.com/blazor-components/blazor-pdf-viewer "Blazor PDF Viewer"), [Flutter](https://www.syncfusion.com/flutter-widgets/flutter-pdf-viewer "Flutter PDF Viewer"),  ASP.NET ([Core](https://www.syncfusion.com/aspnet-core-ui-controls/pdf-viewer "ASP.NET Core PDF Viewer"), [MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls/pdf-viewer "ASP.NET MVC PDF Viewer"), [WebForms](https://www.syncfusion.com/jquery/aspnet-web-forms-ui-controls/pdf-viewer "ASP.NET WebForms PDF Viewer")), [JavaScript](https://www.syncfusion.com/javascript-ui-controls/js-pdf-viewer "JavaScript PDF Viewer"), [Angular](https://www.syncfusion.com/angular-ui-components/angular-pdf-viewer "Angular PDF Viewer"), [React](https://www.syncfusion.com/react-ui-components/react-pdf-viewer "React PDF Viewer"), [Vue](https://www.syncfusion.com/vue-ui-components/vue-pdf-viewer "Vue PDF Viewer"), [Xamarin](https://www.syncfusion.com/xamarin-ui-controls/xamarin-pdf-viewer "Xamarin PDF Viewer"), [UWP](https://www.syncfusion.com/uwp-ui-controls/pdf-viewer "UWP PDF Viewer"),  [WinForms](https://www.syncfusion.com/winforms-ui-controls/pdf-viewer "WinForms PDF Viewer"), and [WPF](https://www.syncfusion.com/wpf-controls/pdf-viewer "WPF PDF Viewer") platforms.

Also, you can contact us through our [support forum](https://www.syncfusion.com/forums "Syncfusion support forum"), [support portal](https://support.syncfusion.com/ "Syncfusion support portal"), or [feedback portal](https://www.syncfusion.com/feedback/wpf "Syncfusion Feedback Portal"). We are always happy to assist you!

## Related blogs

- [Create an Interactive BPMN Editor Using the WPF Diagram Control](https://www.syncfusion.com/blogs/post/create-an-interactive-bpmn-editor-using-the-wpf-diagram-control.aspx "Create an Interactive BPMN Editor Using the WPF Diagram Control blog")
- [Save Memory by Exporting and Importing Annotations in WPF PDF Viewer](https://www.syncfusion.com/blogs/post/save-memory-by-exporting-and-importing-annotations-in-wpf-pdf-viewer.aspx "Save Memory by Exporting and Importing Annotations in WPF PDF Viewer blog")
- [How to Redact Confidential Data Permanently from PDF Files in WPF](https://www.syncfusion.com/blogs/post/redact-confidential-data-permanently-from-pdf-files-in-wpf.aspx "How to Redact Confidential Data Permanently from PDF Files in WPF blog")
- [How to Load Appointments on Demand via Web Services in WPF Scheduler](https://www.syncfusion.com/blogs/post/load-appointments-on-demand-via-web-services-in-wpf-scheduler.aspx "How to Load Appointments on Demand via Web Services in WPF Scheduler blog")