Page 1 of 1

Adding an indicator to annotations with Popups

Posted: Thu May 14, 2020 9:02 am
by IntegraMike
I'm currently trying to add an indicator to annotations with popups but running into issues. My plan was to just draw an icon in the top right corner of the annotation but when doing that I'm losing the graphics of the original annotation. Do you have any advice about how I could go about this (or another implementation that would accomplish my goal of letting users know there's something to be gained by double clicking).

Example:
I have a PdfSquareAnnotation called square that has 30% opacity and is green.
I call square.GetNormalAppearance(true); and then render that and it no longer renders.
Then I draw my image on the PdfGraphics object and that only shows my image.

There's something I'm not understanding between the way the rendered annotation goes from annotation to annotation view that I'm not understanding (as far as I can tell).

Thanks for any help you can provide!

Re: Adding an indicator to annotations with Popups

Posted: Thu May 14, 2020 10:21 am
by Alex
Hello Mike,

You can change the PDF annotation appearance using 2 ways.

WAY 1. Get the PDF annotation normal appearance (an instance of PdfFormXObjectResource class) using PdfAnnotation.GetNormalAppearance method, get PdfGraphics object for PDF annotation appearance using the PdfFormXObjectResource.GetGraphics method, draw necessary graphics using PdfGraphics object.

WAY 2. Create PDF appearance generator (an instance of PdfAnnotationAppearanceGenerator class) for PDF annotation, define drawing logic in PDF appearance generator, set created PDF appearance generator as appearance generator of PDF annotation using the PdfAnnotation.AppearanceGenerator property.

As I have understood you are using WAY 1.

Please use WAY 2 because this way is preferable way and let me know if you will have any question or problem.

Best regards, Alexander

Re: Adding an indicator to annotations with Popups

Posted: Fri May 15, 2020 11:12 am
by IntegraMike
Thanks! That got me 99% of the way there. I have this working for all of the annotation types except for Ink annotations because I'm having an issue getting the path to be drawn.

The annotation has a Point[][] and I'm trying to get that run in a PdfGraphics.DrawX method. I've tried most of them but I'm not getting anything to show up (when I remove my code it works fine). Do you have any advice on what I may be doing wrong?

Code is essentially:

Code: Select all

public override void SetAppearance(PdfAnnotation annotation)
{
    PdfInkAnnotation inkAnnotation = annotation as PdfInkAnnotation;

    using (PdfGraphics graphics = annotation.CreateNormalAppearanceGraphics())
    {
        graphics.DrawX and then some manipulation of inkAnnotation.InkPoints[0] to fit the parameters.
    }
}
Thanks!

Re: Adding an indicator to annotations with Popups

Posted: Fri May 15, 2020 12:13 pm
by Alex
The annotation has a Point[][] and I'm trying to get that run in a PdfGraphics.DrawX method. I've tried most of them but I'm not getting anything to show up (when I remove my code it works fine). Do you have any advice on what I may be doing wrong?
In your code you are defining PDF annotation appearance from scratch - do not do this.

For solving your task for PdfInkAnnotation class you need to do the following steps:
  • Create MyPdfInkAnnotationAppearanceGenerator class derived from PdfInkAnnotationAppearanceGenerator class.
  • Override the SetAppearance method in MyPdfInkAnnotationAppearanceGenerator class.
  • In SetAppearance method:
    • Call SetAppearance method of base class - this action will generate standard normal appearance for PDF ink annotation.
    • Get normal appearance of annotation (instance of PdfFormXObjectResource class) by calling "PdfAnnotation.GetNormalAppearance(false)" method.
    • Open PdfGraphics in append mode for PdfFormXObjectResource class using PdfGraphics.FromForm(PdfFormXObjectResource form, bool append) method.
    • Add necessary graphics to PDF annotation appearance using PdfGraphics object.
Best regards, Alexander