Recreating custom annotations in WindowsFormsHost

Discussions about annotation support.
Post Reply
pcombet
Posts: 6
Joined: Mon Jan 06, 2014 2:27 pm

Recreating custom annotations in WindowsFormsHost

Post by pcombet » Mon Jan 06, 2014 3:44 pm

Hi there

I'm evaluating your GdPicture to use it in a WPF application.
So far I like what we can do with it. We need to work a lot with custom annotiations. The ccordinates of an annotation are stored in a database. When the user reopens a PDF file, the annotations should be recreated programmatically.
I've seen that there is a method AddCustomAnnot in the AnnotationManager class. According to the documentation, this method does not work with COM.
What's the easiest way to recreate a custom Annotation? Do I have to programmatically generate a XMP file with the coordinates and the data needed?

Thank's in advance for your response.

User avatar
Loïc
Site Admin
Posts: 5881
Joined: Tue Oct 17, 2006 10:48 pm
Location: France
Contact:

Re: Recreating custom annotations in WindowsFormsHost

Post by Loïc » Tue Jan 07, 2014 12:02 pm

Hello,

First in WPF you don't have to use the COM edition of GdPicture.NET. Just use the native .NET assembly that WPF fully support.

The way to render custom annotation of a document is exactly the same in Winform and WPF. If you have a look on our winform demo called "Annotation", available in vb.net & C# you will find such code:

Code: Select all

    Private Sub GdViewer1_OnCustomAnnotationPaint(ByVal Annot As GdPicture10.Annotations.AnnotationCustom, ByVal g As System.Drawing.Graphics) Handles GdViewer1.OnCustomAnnotationPaint
        Select Case Annot.ModelID
            Case 1 'triangle annotation, previously defined by the AddCustomAnnotInteractive() function.
                Using gp As New Drawing.Drawing2D.GraphicsPath
                    gp.AddLine(New PointF(Annot.Left - Annot.Width / 2, Annot.Top + Annot.Height / 2), New PointF(Annot.Left, Annot.Top - Annot.Height / 2))
                    gp.AddLine(New PointF(Annot.Left, Annot.Top - Annot.Height / 2), New PointF(Annot.Left + Annot.Width / 2, Annot.Top + Annot.Height / 2))
                    gp.CloseFigure()
                    g.DrawPath(New Pen(Brushes.Red, 0.1), gp)
                End Using
            Case 2 'cross annotation, previously defined by the AddCustomAnnotInteractive() function.
                g.DrawLine(New Pen(Brushes.Red, 0.1), New PointF(Annot.Left - Annot.Width / 2, Annot.Top - Annot.Height / 2), New PointF(Annot.Left + Annot.Width / 2, Annot.Top + Annot.Height / 2))
                g.DrawLine(New Pen(Brushes.Red, 0.1), New PointF(Annot.Left - Annot.Width / 2, Annot.Top + Annot.Height / 2), New PointF(Annot.Left + Annot.Width / 2, Annot.Top - Annot.Height / 2))
        End Select
    End Sub
This snippet demonstrates a way to render customs cross and triangle annotations by using the System.Drawing namespace. I think it is pretty easy to understand but if you have any particular question just let me know :)

With best regards,

Loïc

pcombet
Posts: 6
Joined: Mon Jan 06, 2014 2:27 pm

Re: Recreating custom annotations in WindowsFormsHost

Post by pcombet » Tue Jan 07, 2014 2:08 pm

Hi Loic,

I just found the method AddAnnotationFromXML in the AnnotationManager. This method is exactly what we need. Everything works great with this method. Rendering the annotation was never a problem. The AddCustomAnnot method didn't work in my case, but the AddAnnotationFromXML works great.

Thanks for your answer, though.
Pascal

Schavez70
Posts: 1
Joined: Fri Feb 05, 2016 4:00 pm

Re: Recreating custom annotations in WindowsFormsHost

Post by Schavez70 » Wed Feb 24, 2016 9:31 pm

Could you please provide an example in C# for the Use of AddCustomAnnot

We are coding in C# and we are attempting to use the AddCustomAnnot of the annotation manager class. It is throwing a Stack overflow error after a long pause when calling the following :
AnnotationCustom mycustomAnt = myManager.AddCustomAnnot(2, .5F, .5F,.5F, .5F);

Where myManager is obtained from gdViewer1.GetAnnotationManager();

The following line of code works fine except we can not have the custom annotation be interactive
gdViewer1.AddCustomAnnotInteractive(2);

Gabriela
Posts: 436
Joined: Wed Nov 22, 2017 9:52 am

Re: Recreating custom annotations in WindowsFormsHost

Post by Gabriela » Fri Jan 25, 2019 9:46 am

Hello,

Please find some code snippets here:
https://www.gdpicture.com/guides/gdpicture/web ... ctive.html
https://www.gdpicture.com/guides/gdpicture/web ... nt_EV.html
The Annotations demo you can find within the installation package of the GdPicture toolkit:
https://www.gdpicture.com/guides/gdpicture/web ... tions.html

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest