VintaSoft PDF .NET Plug-in Discussions
Questions, comments and suggestions concerning VintaSoft PDF .NET Plug-in.
Board index < VintaSoft Imaging < VintaSoft PDF .NET Plug-in Discussions
public void SetPdfAnnotationVisibility(WpfImageViewer viewer, int imageIndex, int annotationIndex, bool isVisible)
{
VintasoftImage image = imageViewer.Images[imageIndex];
PdfPage page = PdfDocumentController.GetPageAssociatedWithImage(image);
if (page != null)
{
if (page.Annotations != null)
{
PdfAnnotation annotation = page.Annotations[annotationIndex];
if (!isVisible)
annotation.Flags |= PdfAnnotationFlags.Hidden;
else
annotation.Flags &= PdfAnnotationFlags.Hidden ^ (PdfAnnotationFlags)int.MaxValue;
if (imageViewer.Image == image)
imageViewer.ReloadImage();
else
image.Reload(true);
}
}
}
IMPORTANT: Code above changes PDF document! Do not save PDF document if this is not necessary.public class CustomRenderer : PdfContentRenderer
{
public override void DrawFormXObject(PdfContentRenderingContext context, PdfFormXObjectResource formResource)
{
if (ShowAnnotations)
{
base.DrawFormXObject(context, formResource);
}
}
...
}
This seems to work with our test files and with a call to Vintasoft.Imaging.VintasoftImage.Reload(true) I'm able to switch the visibility "at runtime".But I'm not sure if there can be other XObjects in PDF documents that are not annotations.Yes, not all XObjects represent annotation appearances and you need to hide only XObjects associated with annotation appearances.
public Dictionary<PdfFormXObjectResource, PdfAnnotation> GetAnnotationToAppearanceFormTable(PdfPage page)
{
Dictionary<PdfFormXObjectResource, PdfAnnotation> result = new Dictionary<PdfFormXObjectResource, PdfAnnotation>();
if (page.Annotations != null)
{
foreach (PdfAnnotation annotation in page.Annotations)
{
if (annotation.Appearances != null)
{
PdfFormXObjectResource[] appearanceForms = annotation.Appearances.GetAllAppearances();
foreach (PdfFormXObjectResource appearanceForm in appearanceForms)
result[appearanceForm] = annotation;
}
}
}
return result;
}
Best regards, Alexander