Annotations like comments, highlights, and markups are frequently added to PDF documents during editing and review processes. However, in some cases, you may need to remove these annotations before finalizing the document. In this blog post, we’ll demonstrate how to remove annotations from a PDF programmatically in C#.
Why Remove Annotations from PDF?
Annotations are useful during the editing process, but they can make the document appear cluttered and unprofessional when shared with clients or for final publishing. Removing these annotations ensures a clean, polished PDF ready for distribution, while protecting sensitive review data from being shared unintentionally.
Remove Annotations from PDF - C# API Installation
You can remove annotations from any PDF document by installing Conholdate.Total for .NET in your system. Simply configure it by downloading the DLL file or run the following NuGet installation command:
PM> NuGet\Install-Package Conholdate.Total
Remove Annotations from PDF in C#
The following steps outline the algorithm for removing annotations from PDF documents:
- Load the PDF Document: We initiate the Redactor class to load the PDF file from the specified path.
- Apply Annotation Removal: We use the DeleteAnnotationRedaction method to remove annotations that contain specific words like “use”, “show”, or “describe”. The method uses a regular expression to find annotations containing these keywords.
- Save the Document: After applying the redaction, we save the updated document. The SaveOptions allows us to add a suffix to the file name and save the output PDF in its original format (without rasterizing it).
The following code snippet demonstrates how to remove annotations from PDF in C#:
Free Evaluation License
You can request a free temporary license to test different methods exposed by the API and test custom requirements while working with annotations in PDF documents.
Summing Up
Removing annotations from PDF documents is a crucial step when preparing files for distribution or publishing. You can easily automate this task and ensure that your PDFs are clean and professional by following these guidelines. In case of any questions, please write to us at forum.
FAQs
Can I remove specific annotations based on their content?
Yes, you can remove annotations containing specific text or patterns using regular expressions.
Is this method applicable for large PDFs with many annotations?
Yes, it can efficiently processes large PDFs, even those with numerous annotations.
What happens if I don’t specify a pattern for annotation removal?
If no pattern is provided, you can still remove all annotations from the document, regardless of their content.
Can I undo the removal of annotations?
Once annotations are removed and the document is saved, the action cannot be undone, so keeping a backup is recommended.