1
1
using Syncfusion . Pdf . Graphics ;
2
2
using Syncfusion . Pdf . Interactive ;
3
3
using Syncfusion . Pdf . Parsing ;
4
- using System ;
5
- using System . Collections . Generic ;
6
4
using System . Drawing ;
7
5
using System . IO ;
8
- using System . Linq ;
9
- using System . Text ;
10
- using System . Threading . Tasks ;
11
6
using System . Windows ;
12
7
using System . Windows . Controls ;
13
8
using System . Windows . Controls . Primitives ;
14
- using System . Windows . Data ;
15
- using System . Windows . Documents ;
16
9
using System . Windows . Input ;
17
- using System . Windows . Media ;
18
- using System . Windows . Media . Imaging ;
19
- using System . Windows . Navigation ;
20
- using System . Windows . Shapes ;
21
10
22
11
namespace UriAnnotation
23
12
{
@@ -44,36 +33,41 @@ private void BtnLoad_Click(object sender, RoutedEventArgs e)
44
33
45
34
//Draw the border.
46
35
docView . LoadedDocument . Pages [ 0 ] . Graphics . DrawRectangle ( PdfPens . Red , new RectangleF ( 10 , 10 , 30 , 30 ) ) ;
47
-
48
-
36
+
49
37
//Create a new Uri Annotation.
50
38
PdfUriAnnotation uriAnnotation = new PdfUriAnnotation ( new RectangleF ( 10 , 10 , 30 , 30 ) , "http://www.google.com" ) ;
51
39
//Set Text to uriAnnotation.
52
40
uriAnnotation . Text = "Uri Annotation" ;
53
41
//Add this annotation to a new page.
54
42
docView . LoadedDocument . Pages [ 0 ] . Annotations . Add ( uriAnnotation ) ;
55
- //Save the document to disk .
43
+ //Save the document and reload it into viewer .
56
44
MemoryStream stream = new MemoryStream ( ) ;
57
45
lDoc . Save ( stream ) ;
58
46
docView . Load ( stream ) ;
47
+ //Get the annotation page index and bounds.
59
48
annotationPageIndex = 0 ;
60
49
annotationBounds = uriAnnotation . Bounds ;
61
- //annotationBounds = convertor.ConvertToPixels(annotationBounds, PdfGraphicsUnit.Point);
50
+ //Create the tooltip with content and placement target.
62
51
TextBlock textBlock = new TextBlock ( ) ;
63
52
textBlock . Text = "Uri Annotation" ;
64
53
tooltip . PlacementTarget = docView ;
65
54
tooltip . Content = textBlock ;
55
+ //Subscribe page mouse move event of WPF PdfViewer.
66
56
docView . PageMouseMove += PdfViewer_PageMouseMove ;
67
57
}
68
58
69
59
private void PdfViewer_PageMouseMove ( object sender , Syncfusion . Windows . PdfViewer . PageMouseMoveEventArgs args )
70
60
{
61
+ //Ensure the annotation bounds are not empty.
71
62
if ( annotationBounds != RectangleF . Empty )
72
63
{
64
+ //Convert the position from pixels to point values.
73
65
float x = convertor . ConvertFromPixels ( ( float ) args . Position . X , PdfGraphicsUnit . Point ) ;
74
66
float y = convertor . ConvertFromPixels ( ( float ) args . Position . Y , PdfGraphicsUnit . Point ) ;
67
+ //Ensure the retrieved page index matches the annotation page index, and then compare the converted position value with the annotation bounds.
75
68
if ( args . PageIndex == annotationPageIndex && annotationBounds . Contains ( x , y ) )
76
69
{
70
+ //change the cursor and set the tooltip position.
77
71
docView . Cursor = Cursors . Hand ;
78
72
docView . ForceCursor = true ;
79
73
if ( ! tooltip . IsOpen )
0 commit comments