create a custom link and the annotation display in highlight color

My goal is to create a custom link and the annotation display in highlight color base on user preferences.

I recently tried about PDFView sample, but I haven’t make it work on adding a new annotation by using Custom Link Create Tool. The code for creating annotation has never run because the pg is not nothing.

if I changed the If pg is nothing from true to false on onMouseUp function on MyPDFview then the code of the If block can run. I added the code to make a rectangle on the top as like the code on the Annotation Test project. The saved file didn’t show the rectangle. I debug the code and found that the value of _start_pt.Y and pt_arr(1).Y is same for creating the rect. Also it is the same value for pt_arr(0).X and pt_arr(1).X. Therefore I assigned the value of the PointF then the rectangle show on the saved file, not the doc on the screen. Also I can click the annotation to goto another page on the saved file.

My question are:

  1. How can I get the right position onMouseUp and show on the opening document?

  2. I know there is highlight annotation in PDFSDK, how can I assign the action on it; goto another page or hyperlink as creating the link in code. If the highlight annotation doesn’t accept the action, would you tell what I should do in order to fit my goal?

There is my code snippet on OnMouseUp function

If Not (action Is Nothing) Then

’ Create link annotation position rectangle in PDF page coordinate system.

Dim screen2page As Matrix = GetDeviceTransform(_cur_page)

screen2page.Invert()

Dim pt_arr As PointF() = {_start_pt, _end_pt}

screen2page.TransformPoints(pt_arr)

Dim pos As Rect = New Rect(pt_arr(0).Y, pt_arr(0).X, pt_arr(1).Y + 50, pt_arr(1).X + 300)

pos.Normalize()

Dim link As Link = link.Create(doc.GetSDFDoc, pos, action)

’ Todo?

’ Create link appearances based on user preferences.

Dim s As Annot.BorderStyle.Style = Annot.BorderStyle.Style.e_solid

Dim bs As Annot.BorderStyle = New Annot.BorderStyle(s, 1)

link.SetBorderStyle(bs)

link.SetColor(New ColorPt(0.145, 0.2509, 0.3803))

’ Create other annotation and action types…

’ …

link.RefreshAppearance()

pg.AnnotPushBack(link)

Dim output_path As String = “C:\Test”

doc.Save(output_path + “annotation_Sept18_1.pdf”, SDF.SDFDoc.SaveOptions.e_linearized)

End If

Thanks in advance.

If you are targeting Windows, and .Net 4+, then I would recommend using PDFViewWPF.

PDFViewWPF is being actively developed, and improved, and one of the big differences is a lot more of the code is/will be made available to you. This makes the PDFViewWPF control a lot more customizable than PDFViewCtrl.

I download the PDFNet64DotNet4 and read the sample PDFViewWPFCS_2010. In the sample, there is on adding customer annotation as PDFViewVB project did. I have no clue how to add the customer annotation if I use PDFNet64DotNet4 . Would you tell me how can I do to test it for make sure it is fit my goal, so I can report to my manger whether we can use it for development our project.

Hi BMW,

With PDFViewWPF, it is very straight forward to create a custom tool. All you need to do is to register for the appropriate events of the PDFViewWPF. In particular, PDFViewWPF.MouseLeftButtonDown, MouseLeftButtonUp, and MouseMoved are often enough to create a rudimentary tool. Please see the following link (https://groups.google.com/d/msg/pdfnet-sdk/-cStPF6VRnQ/KOVG_eyNKnMJ) for some sample code. This sample will explain how to create and draw a rectangle and operate in different coordinate spaces (page vs viewer, etc) which is a good starting point. Also note that in our next official release, all the tools used with PDFViewWPF will be part of the sample, making it easy to modify and edit their behaviour to suit your application. The tools operate using the events I described above (plus a lot of other events).

Best Regards,
Tomas Hofmann