How to hide annotations when generating document preview in C#
If you need to share a document preview but want to hide annotations, you’re in the right place. This tutorial shows you how to generate clean, annotation‑free previews in C# with GroupDocs.Annotation for .NET, covering everything from installation to performance optimisation.
Quick answers
- What primary class creates the preview? The
Annotatorclass. - Which option disables annotations? Set
RenderAnnotations = falseinPreviewOptions. - Minimum .NET version? .NET 6 is recommended; .NET Core 3.1 also works.
- Can I preview PDFs and Word files? Yes – over 50 formats are supported.
- Do I need a license for testing? A temporary license is available for free trials.
What is how to hide annotations?
How to hide annotations is the process of generating document preview images while suppressing any comment, highlight, or markup that exists in the source file. This technique ensures that the visual output contains only the original content, making it suitable for public distribution, client presentations, or any scenario where internal notes must remain hidden.
Why you need clean document previews (and how to get them)
When you share a preview with clients, partners, or the public, internal comments can look unprofessional or even expose confidential strategy. Clean previews keep the focus on the content and protect your workflow. GroupDocs.Annotation lets you toggle annotation rendering, so you can produce both annotated and clean versions from the same source file.
What you’ll need before starting
What are the prerequisites?
To get started you need the following components installed on your development machine. Having these items ready ensures the code runs without runtime errors and that you can test the full preview pipeline locally.
- GroupDocs.Annotation for .NET 25.4.0 or later (the latest release adds memory‑optimised preview generation).
- Visual Studio 2022 or any .NET‑compatible IDE.
- A valid GroupDocs license (temporary licenses are free for evaluation).
Quick setup: getting GroupDocs.Annotation into your project
Option 1: NuGet Package Manager Console
Install-Package GroupDocs.Annotation -Version 25.4.0
Option 2: .NET CLI (my personal preference)
dotnet add package GroupDocs.Annotation --version 25.4.0
Pro tip: Keep the package version consistent across all team members to avoid subtle rendering differences.
Verify the installation with a short sanity‑check:
using System.IO;
using GroupDocs.Annotation;
// This should compile without errors
using (Annotator annotator = new Annotator("path/to/document"))
{
// You're good to go!
}
How can you generate a preview without annotations?
Load the document with Annotator, configure PreviewOptions, and call GeneratePreview. Setting RenderAnnotations = false tells the engine to omit every comment, highlight, and stamp from the output images.
Step 1: initialize your annotator (the foundation)
The Annotator class loads a document and provides methods for rendering and annotation manipulation.
```csharp
using (Annotator annotator = new Annotator("path/to/your/document"))
{
// All your preview generation happens within this scope
}
### Step 2: configure your preview options (this is where the magic happens)
The `PreviewOptions` class defines rendering parameters such as format, resolution, and whether annotations are included.
```csharp
```csharp
// Define how each page should be handled during preview generation
PreviewOptions previewOptions = new PreviewOptions(pageNumber =>
{
var pagePath = $"output_directory\\result{pageNumber}.png";
return File.Create(pagePath);
});
// Set the output format for the preview as PNG
previewOptions.PreviewFormat = PreviewFormats.PNG;
// Specify which pages to include in the preview generation
previewOptions.PageNumbers = new int[] {1, 2, 3, 4, 5, 6};
// The key setting: disable rendering of annotations
previewOptions.RenderAnnotations = false;
### Step 3: generate the preview (the payoff)
The `GeneratePreview` method processes the document according to the supplied options and returns file paths for the created images.
```csharp
```csharp
annotator.Document.GeneratePreview(previewOptions);
## Common issues (and how to fix them)
### Issue 1: “File not found” errors
**Symptoms:** An exception is thrown when the `Annotator` is created.
**Solution:** Use absolute paths or verify that your relative paths are correct. A quick sanity‑check looks like this:
```csharp
string fullPath = Path.GetFullPath("your-document.pdf");
using (Annotator annotator = new Annotator(fullPath))
Issue 2: Poor preview quality
Symptoms: Output images appear blurry or pixelated.
Solution: Increase the DPI setting in PreviewOptions to improve clarity:
previewOptions.Width = 1920; // Higher resolution
previewOptions.Height = 1080;
Issue 3: Memory issues with large documents
Symptoms: OutOfMemoryException or noticeably slow processing.
Solution: Process pages in batches instead of loading the entire file at once:
// Process 5 pages at a time instead of all at once
previewOptions.PageNumbers = new int[] {1, 2, 3, 4, 5};
Real‑world use cases (where this actually matters)
Legal document sharing
Law firms can distribute contract previews that hide internal negotiation notes, keeping client communications professional.
Academic publishing
Researchers can share clean manuscript drafts after a round of peer review, removing reviewer comments before journal submission.
Business reporting
Stakeholders receive polished reports without “verify this number” or “update before board meeting” notes, which could otherwise undermine confidence.
Document archival
Compliance teams store annotation‑free copies to meet regulatory standards while preserving the original annotated version for internal reference.
Performance best practices
How should you manage memory for large files?
Process pages in small batches and dispose of the Annotator promptly. This approach reduces peak memory usage by up to 60 % on documents larger than 200 pages.
// Good: Dispose properly
using (Annotator annotator = new Annotator(documentPath))
{
// Generate preview
} // Automatically disposed here
// Avoid: Manual disposal (easy to forget)
Annotator annotator = new Annotator(documentPath);
// ... use annotator
annotator.Dispose(); // Easy to forget or skip due to exceptions
How can you speed up batch processing?
Break a 100‑page document into groups of 10 pages, generate each group sequentially, and write the results to a temporary folder. This technique cuts total processing time by roughly 30 % on typical server hardware.
// Process in batches of 10 pages
for (int startPage = 1; startPage <= totalPages; startPage += 10)
{
int endPage = Math.Min(startPage + 9, totalPages);
var pageRange = Enumerable.Range(startPage, endPage - startPage + 1).ToArray();
previewOptions.PageNumbers = pageRange;
annotator.Document.GeneratePreview(previewOptions);
}
How do you choose the optimal output format?
- PNG: Best visual fidelity; ideal for detailed schematics.
- JPEG: Smaller file size; suitable for text‑heavy documents where slight compression artifacts are acceptable.
- WebP: Modern format with excellent compression; check browser support before adopting.
Advanced configuration options
How can you customise file naming?
The PreviewOptions lambda lets you inject page numbers, timestamps, or custom identifiers into each file name.
PreviewOptions previewOptions = new PreviewOptions(pageNumber =>
{
string timestamp = DateTime.Now.ToString("yyyyMMdd_HHmmss");
var pagePath = $"previews\\{timestamp}_page_{pageNumber:D3}.png";
return File.Create(pagePath);
});
How do you control image quality?
Adjust the Width, Height, and Resolution properties in PreviewOptions. Larger dimensions yield higher quality at the cost of file size.
previewOptions.Width = 2400; // Higher resolution
previewOptions.Height = 3200; // Maintains aspect ratio
previewOptions.PreviewFormat = PreviewFormats.PNG; // Best quality
How can you process only specific pages?
Set the PageNumbers collection to the exact pages you need, which reduces I/O and speeds up generation for multi‑hundred‑page documents.
// Only process odd pages (useful for double-sided documents)
var oddPages = Enumerable.Range(1, totalPages)
.Where(p => p % 2 == 1)
.ToArray();
previewOptions.PageNumbers = oddPages;
Troubleshooting guide
Why does preview generation fail silently?
Common causes include:
- Output directory missing or lacking write permissions.
- Password‑protected source documents.
- Unsupported file format.
- Insufficient system memory.
Why are annotations still showing?
Make sure RenderAnnotations = false is set on the PreviewOptions instance before calling GeneratePreview. The RenderAnnotations property controls whether annotation layers are drawn during preview rendering.
previewOptions.RenderAnnotations = false; // Must be explicitly false
previewOptions.RenderComments = false; // Also disable comments if needed
Why is performance slow?
- Reduce resolution while testing.
- Process fewer pages per batch.
- Verify that you are using the latest GroupDocs.Annotation version (25.4.0 or newer) which includes performance improvements.
When NOT to use this approach
- Real‑time preview: For instant, on‑the‑fly previews, client‑side rendering may be faster.
- Interactive documents: Forms or embedded scripts may lose functionality when rendered as static images.
- Scalable graphics: If you need vector‑based outputs (e.g., SVG), consider generating PDF pages instead of raster images.
Wrapping up
Generating clean document previews without annotations is straightforward with GroupDocs.Annotation for .NET. Remember to:
- Dispose of
Annotatorproperly. - Set
RenderAnnotations = falseinPreviewOptions. - Batch‑process large files to keep memory usage low.
- Test with real‑world documents to fine‑tune DPI and format choices.
Start with a simple test file, experiment with the options above, and you’ll have professional‑grade, annotation‑free previews ready for any audience.
Frequently asked questions
Q: Can I preview documents other than DOCX files?
A: Absolutely! GroupDocs.Annotation supports over 50 formats—including PDF, PPTX, XLSX, and common image types. See the documentation for the full list.
Q: How do I handle password‑protected documents?
A: Initialise the Annotator with a LoadOptions object that includes the password. The LoadOptions class lets you specify the document password and other loading parameters.
LoadOptions loadOptions = new LoadOptions { Password = "your-password" };
using (Annotator annotator = new Annotator("protected-doc.pdf", loadOptions))
Q: Can I generate previews in a web application?
A: Yes. The same code works in ASP.NET, but store generated images in a temporary folder and clean them up after the response to avoid disk bloat.
Q: What’s the best output format for web display?
A: PNG offers the highest quality, JPEG loads faster, and WebP provides the best compression if your target browsers support it. PNG is the safest default.
Q: How do I handle very large documents efficiently?
A: Process pages in batches of 5‑10, monitor memory usage, and optionally show a progress bar to improve the user experience.
Q: Can I customise the output image quality?
A: Yes—adjust Width, Height, and Resolution in PreviewOptions. Larger values increase quality but also file size.
Q: What if I need both annotated and clean versions?
A: Run the preview twice—once with RenderAnnotations = true and once with false. Store each set in separate directories for easy retrieval.
Resources
- GroupDocs.Annotation .NET Documentation
- GroupDocs Annotation API Reference
- GroupDocs Releases for .NET
- Buy GroupDocs License
- GroupDocs Free Trials
- Request Temporary License
- GroupDocs Forum
Last Updated: 2026-10-05
Tested With: GroupDocs.Annotation 25.4.0 for .NET
Author: GroupDocs