HOWTO: Take Control of DocumentAnnotationViewer Automatic Annotation Loading


By default DocumentAnnotationViewer control will automatically extract embedded annotation data from JPEG, TIFF and PDF files. This can be problematic particularly with PDF files which can contain annotations that do not map directly to DotImage annotation types.    

The AnnotationDataProvider property of the DocumentAnnotationViewer is what controls how annotations get loaded into the viewer. If you want to change the way that annotations are loaded you will need to need to create a custom AnnotationDataProvider by implementing the IAnnotationDataProvider interface. Some examples are included below.

Example 1: Turn off all annotations

public class TestAnnotationDataProvider : IAnnotationDataProvider
{
    public TestAnnotationDataProvider(PointF viewerResolution)
    {
    }

    public LayerData GetLayerData(int frameIndex)
    {
        return new LayerData();
    }

    public void PrepareForExtraction(Stream stream, int frameIndex)
    {
    }

    public void PrepareForExtraction(string fileName, int frameIndex)
    {
    }

    public void PrepareForExtraction(RandomAccessImageSource source, int frameIndex)
    {
    }

    public void PrepareForExtraction(AtalaImage image)
    {
    }
}

Example 2: Remove only specific annotation types

public class TestAnnotationDataProvider : IAnnotationDataProvider
{
    private EmbeddedAnnotationDataProvider adp;
    public TestAnnotationDataProvider(PointF viewerResolution)
    {
        adp = new EmbeddedAnnotationDataProvider(viewerResolution);
    }

    public LayerData GetLayerData(int frameIndex)
    {
        LayerData ld = adp.GetLayerData(frameIndex);
        for(int i=ld.Items.Count-1; i>=0; i--)
        {
            if (ld.Items[i] is PdfLinkData)
            {
                ld.Items.RemoveAt(i);
            }
        }
        return ld;
    }

    public void PrepareForExtraction(Stream stream, int frameIndex)
    {
        adp.PrepareForExtraction(stream, frameIndex);
    }

    public void PrepareForExtraction(string fileName, int frameIndex)
    {
        adp.PrepareForExtraction(fileName, frameIndex);
    }

    public void PrepareForExtraction(RandomAccessImageSource source, int frameIndex)
    {
        adp.PrepareForExtraction(source, frameIndex);
    }

    public void PrepareForExtraction(AtalaImage image)
    {
        adp.PrepareForExtraction(image);
    }
}

Original Article

Q10474 - HOWTO: Take Control of DocumentAnnotationViewer Automatic Annotation Loading

Last Update

2026-10-01 - TD - (Fairly major reformatting)