Page 1 of 1

Recreating custom annotations in WindowsFormsHost

Posted: Mon Jan 06, 2014 3:44 pm
by pcombet
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.

Re: Recreating custom annotations in WindowsFormsHost

Posted: Tue Jan 07, 2014 12:02 pm
by Loïc
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

Re: Recreating custom annotations in WindowsFormsHost

Posted: Tue Jan 07, 2014 2:08 pm
by pcombet
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

Re: Recreating custom annotations in WindowsFormsHost

Posted: Wed Feb 24, 2016 9:31 pm
by Schavez70
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);

Re: Recreating custom annotations in WindowsFormsHost

Posted: Fri Jan 25, 2019 9:46 am
by Gabriela
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