Skip to main content
Boris56
Known Participant
April 16, 2020
Question

How to get color of annotations

  • April 16, 2020
  • 1 reply
  • 383 views

In the program for the selected fragment, I create an annotation,
I set the color of the annotation using the PDAnnotSetColor method.
The fragment is painted in the desired color. Next, I need to look at all the annotations created on the page and determine their color. I wrote this code:

int numAnnots = PDPageGetNumAnnots(pdPage);
for (int i = 0; i < numAnnots; i++) {
    PDAnnot pdAnnot = PDPageGetAnnot(pdPage, i);
    if (PDAnnotGetSubtype(pdAnnot) == ASAtomFromString("Highlight")) {
	PDColorValue pdColorValue;
	if (PDAnnotGetColor(pdAnnot, pdColorValue)) {
		if (pdColorValue->space == PDDeviceRGB) {
			ASFixed red = pdColorValue->value[0];
			ASFixed green = pdColorValue->value[1];
			ASFixed blue = pdColorValue->value[2];
			double value1 = ASFixedToFloat(red);
			double value2 = ASFixedToFloat(green);
			double value3 = ASFixedToFloat(blue);
		}
	}
	}
}

but an exception is thrown in the statement if  (PDAnnotGetColor (pdAnnot, pdColorValue)). Where am I wrong?

This topic has been closed for replies.

1 reply

Boris56
Boris56Author
Known Participant
April 17, 2020

Necessity is the mother of invention.
Since I could not get the color of the annotation, I went the other way. The color set of annotations for me is strictly fixed, so when creating an annotation using the PDAnnotSetDate method, I write down the color number (I renumber all the colors beforehand) as the month number on the date of creating the annotation. In the right place, using the PDAnnotGetDate method, I read the month number and thereby get the color number.