Hello.
We are using the Vintasoft.Imaging.Wpf.UI.WpfImageViewer from the Imaging .NET SDK (Standard, WPF, Reader) to display PDF Documents (without the Annotation .NET Plug-in). The viewer shows also all PDF annotations.
A new requirement is to toggle the visiblity of the annotations. The user should be able to hide and show the annotations.
How can we temporarily hide the annotations without modifying the PDF document itself?
Thanks in advance!
Kind regards,
Johannes
Hiding Annotations
Moderator: Alex
Re: Hiding Annotations
Hello Johannes,
You need use the PDF content renderer if you want to control the rendering process of PDF page. Please read more info here: http://www.vintasoft.com/docs/vsimaging ... ntent.html
Best regards, Alexander
You need use the PDF content renderer if you want to control the rendering process of PDF page. Please read more info here: http://www.vintasoft.com/docs/vsimaging ... ntent.html
Best regards, Alexander
Re: Hiding Annotations
Hello Johannes,
Here is a code snippet that shows how to show/hide annotation in PDF document:
IMPORTANT: Code above changes PDF document! Do not save PDF document if this is not necessary.
Best regards, Alexander
Here is a code snippet that shows how to show/hide annotation in PDF document:
Code: Select all
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);
}
}
}
Best regards, Alexander
-
- Posts: 2
- Joined: Tue May 03, 2016 10:41 am
Re: Hiding Annotations
Hello Alex,
before I saw your second answer I had written a custom renderer which prevents to call DrawFormXObject() of the base renderer if annotations should be hidden:
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. Theses XObjects should be shown even if the annotations are hidden. Can I filter for a certain ResourceType? What is your opinion?
Nevertheless I'll try your second solution. Thank you!
Kind regards, Johannes
before I saw your second answer I had written a custom renderer which prevents to call DrawFormXObject() of the base renderer if annotations should be hidden:
Code: Select all
public class CustomRenderer : PdfContentRenderer
{
public override void DrawFormXObject(PdfContentRenderingContext context, PdfFormXObjectResource formResource)
{
if (ShowAnnotations)
{
base.DrawFormXObject(context, formResource);
}
}
...
}
But I'm not sure if there can be other XObjects in PDF documents that are not annotations. Theses XObjects should be shown even if the annotations are hidden. Can I filter for a certain ResourceType? What is your opinion?
Nevertheless I'll try your second solution. Thank you!
Kind regards, Johannes
Re: Hiding Annotations
Yes, not all XObjects represent annotation appearances and you need to hide only XObjects associated with annotation appearances.But I'm not sure if there can be other XObjects in PDF documents that are not annotations.
Here is a code snippet that allows to get dictionary with annotation appearances for specified PDF page:
Code: Select all
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;
}