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
/// <summary>
/// Scrolls to the annotation.
/// </summary>
/// <param name="viewer">The image viewer.</param>
/// <param name="image">The image that contains PDF annotation.</param>
/// <param name="annotation">The PDF annotation.</param>
/// <exception cref="System.ArgumentNullException">Thrown if <i>viewer</i> or <i>image</i> or <i>annotation</i> is <b>null</b>.</exception>
public void ScrollToAnnotation(ImageViewer viewer, VintasoftImage image, PdfAnnotation annotation)
{
if (viewer == null)
throw new ArgumentNullException("viewer");
if (image == null)
throw new ArgumentNullException("image");
if (annotation == null)
throw new ArgumentNullException("annotation");
// get image index in image viewer
int focusedIndex = viewer.Images.IndexOf(image);
// if image viewer does not contain image
if (focusedIndex == -1)
return;
// update focused index in image viewer
viewer.FocusedIndex = focusedIndex;
// get PDF page
PdfPage page = PdfDocumentController.GetPageAssociatedWithImage(image);
// get transform from annotation space to the image space
AffineMatrix transformFromAnnotationToImage = page.GetTransformFromPageSpaceToImageSpace(image.Resolution);
// get annotation bounding box in image space
RectangleF annotationBoundingBoxInImageSpace = PointFAffineTransform.TransformBoundingBox(
PointFAffineTransform.FromMatrix(transformFromAnnotationToImage),
annotation.Rectangle);
// get the image region, which is visible in image viewer
RectangleF imageVisibleRect = viewer.ViewerState.ImageVisibleRect;
// if annotation region is not visible in the image viewer
if (!imageVisibleRect.Contains(annotationBoundingBoxInImageSpace.Left, annotationBoundingBoxInImageSpace.Top) ||
!imageVisibleRect.Contains(annotationBoundingBoxInImageSpace.Right, annotationBoundingBoxInImageSpace.Bottom))
{
// get annotation bounding box center in image space
PointF annotationBoundingBoxCenter = new PointF(
annotationBoundingBoxInImageSpace.X + annotationBoundingBoxInImageSpace.Width / 2,
annotationBoundingBoxInImageSpace.Y + annotationBoundingBoxInImageSpace.Height / 2);
// scroll to the annotation bounding box center
viewer.ScrollToPoint(annotationBoundingBoxCenter);
}
}
Best regards, Alexander