0

I'm trying to reuse the color of a highlight annotation after a pdf document and it's highlights have been saved.

I add an annotation and assign a color this way:

if (isCustomColor)
         {
             ColorPt color = markingColors[m_editColor];
             hightlightAnnot.SetColor(color,3);
             hightlightAnnot.RefreshAppearance();
         }

         pdftron.PDF.Page page = doc.GetPage(selectionPageNum);

         TextExtractor txtExtractor = new TextExtractor();
         txtExtractor.Begin(page, hightlightAnnot.GetRect());
         hightlightAnnot.SetContents(txtExtractor.GetAsText());

         doc.Lock();
         page.AnnotPushBack(hightlightAnnot);
         doc.Unlock();

markingscolors is a dictionary with colors that i add in the constructor:

   markingColors.Add(MarkingColor.black,  new ColorPt(113 / 255.0, 113 / 255.0, 113 / 255.0));
        markingColors.Add(MarkingColor.yellow, new ColorPt(1, 1, 0));
        markingColors.Add(MarkingColor.red,    new ColorPt(1, 0, 0));
        markingColors.Add(MarkingColor.green,  new ColorPt(0, 1, 0));
        markingColors.Add(MarkingColor.blue,   new ColorPt(45/255.0, 126/255.0, 205/255.0));

The problem is that i can't retrieve the color of an annotation if it has been set to black or blue (double type values) after saving and reopening the pdf.

to check if colors are equal (to get highlights with a specific color for exporting them to an rtf document and adding indentations based on the colors in the rtf document):

 private bool ColorsEqual(ColorPt color1, ColorPt color2)
    {

        if (color1.Get(0) != color2.Get(0))
        {
            return false;
        }
        if (color1.Get(1) != color2.Get(1))
        {
            return false;
        }
        if (color1.Get(2) != color2.Get(2))
        {
            return false;
        }
        return true;
    }

I call it this way:

 foreach (MarkingColor color in colors)
                    {
                        if (ColorsEqual(annotation.GetColorAsRGB(), markingColors[color]))
                        {
                            int indentation = indentations[color];
                            for (int j = 1; j <= indentation; j++)
                            {
                                text += " ";
                            }
                            text += annotation.GetContents();
                            break;
                        }
                    }

but the color of the annotation always returns an integer value instead of a double, that's why black and blue aren't working... Also if the extraction is done immediatly instead of reopening the pdf, there's no problem and the colors are working perfectly

How can this be solved?

DennisVA
  • 2,068
  • 1
  • 25
  • 35
  • It would be better if you explained why you are "reusing" the color. What is it that you are trying to accomplish? Why is this important? – Ryan Jul 07 '16 at 16:48
  • I need to extract all highlighted text with indentations based on their color – DennisVA Jul 08 '16 at 06:43
  • i kinda solved it by setting a tag in the content of the annotation, but it's really weird why it's not working – DennisVA Jul 08 '16 at 06:58
  • Yes, I was going to suggest tagging the Annotation with your own key. annot.GetSDFObj().PutName("my_key","my_value"). Maybe you need to rewrite this question to be what you are really trying to accomplish. Also, there are two colors associated with an annotation. The stroke and the fill. You need to clarify which. Maybe a screenshot would help. – Ryan Jul 08 '16 at 16:54
  • Oh i didn't know there was a method for putting keyvalue pairs in it, going to use that instead of putting a tag with setcontents. I'm using the SetColor method on my highlight annotation to set the color btw. Again thx for your help – DennisVA Jul 08 '16 at 23:40
  • Hi Ryan, i have another question if you don't mind: how can i remove the invisible border aroud and underline annotation? i tried setting the borderstyle width to 0 but then it's completely gone... – DennisVA Jul 11 '16 at 14:26
  • I think it would be best if you created a new SO question regarding the border. And of course provide more info (screenshots) as it is unclear what you are asking. – Ryan Jul 11 '16 at 17:01
  • Here you go: http://stackoverflow.com/questions/38347803/underlining-with-pdfnet-results-in-different-line-thickness – DennisVA Jul 13 '16 at 09:51

0 Answers0