Show and Hide Annotations Based on Author in WPF PDF Viewer
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (173).NET Core  (29).NET MAUI  (203)Angular  (107)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (40)Black Friday Deal  (1)Blazor  (211)BoldSign  (13)DocIO  (24)Essential JS 2  (106)Essential Studio  (200)File Formats  (65)Flutter  (132)JavaScript  (219)Microsoft  (118)PDF  (81)Python  (1)React  (98)Streamlit  (1)Succinctly series  (131)Syncfusion  (897)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (50)Windows Forms  (61)WinUI  (68)WPF  (157)Xamarin  (161)XlsIO  (35)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (146)Chart  (127)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (618)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (39)Extensions  (22)File Manager  (6)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (501)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (42)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (381)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (17)Web  (582)What's new  (323)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Show and Hide Annotations Based on Author in WPF PDF Viewer

Show and Hide Annotations Based on Author in WPF PDF Viewer

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 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 and install the Syncfusion WPF PDF Viewer 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.
    <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 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.

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 property of the WPF PDF Viewer containing the details of the annotation.

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

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

//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 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 documentation.

Refer to the following code example.

//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 for more details.

Show hidden annotation

Similarly, you can show the hidden annotations using the ShowAnnotation method.

Refer to the following code example.

//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
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.

GitHub reference

Also, check out the example to show and hide annotations based on author in a PDF using the WPF PDF Viewer.

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 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 BlazorFlutter,  ASP.NET (CoreMVCWebForms), JavaScriptAngularReactVueXamarinUWP,  WinForms, and WPF platforms.

Also, you can contact us through our support forumsupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed