Saving the color of an annotation in pdftron (pdfnet winforms)

浪尽此生 提交于 2019-12-12 02:34:39

问题


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?

来源:https://stackoverflow.com/questions/38240575/saving-the-color-of-an-annotation-in-pdftron-pdfnet-winforms

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!