Copy link to clipboard
Copied
I'm trying to develpe a plugin, to insert some annotations into the PDF file. But I don't know how use the function PDAnnotSetColor , please help to give me an detail example to change the color of annotation.
Fill in the color space and color value of a PDColorRec. Pass the annoy and color. It must be an RGB color space. please let us know which parts of documentation or my explanation are unclear.
Copy link to clipboard
Copied
Fill in the color space and color value of a PDColorRec. Pass the annoy and color. It must be an RGB color space. please let us know which parts of documentation or my explanation are unclear.
Copy link to clipboard
Copied
Dear Test Screen Name,
Sorry, I'm just a beginner of developer based on C++. Please help to finallize the following code for me, I want to change the color of the annotation to red, how to do? Thanks.
PDColorValue color;
PDPage page = NULL;
PDAnnot annot,textannot;
char* ptr = "This is initial text";
//Create an ASFixed object and define its borders
ASFixedRect fr;
fr.left = ASInt32ToFixed(36);
fr.top = ASInt32ToFixed(792-36);
fr.right = ASInt32ToFixed(136);
fr.bottom = ASInt32ToFixed(792-136);
//Create an ASPage object
page = PDDocAcquirePage(myPDDoc, 0);
//Create a PDAnnot object
annot = PDPageCreateAnnot (page, ASAtomFromString("FreeText"),&fr);
//Cast the PDAnnot object to a PDTextAnnot object
textannot = CastToPDTextAnnot(annot);
//Open the annotation, set the text, and add it to a page
PDTextAnnotSetOpen (textannot, true);
PDTextAnnotSetContents (textannot, ptr, strlen (ptr));
PDPageAddAnnot(page,-2, textannot);
Copy link to clipboard
Copied
Do not declare a PDColorValue, this is the name of the pointer. Instead, declare a value of type PDColorValueRec. And pass the ADDRESS of the value to PDAnnotSetColor. This method (XXX pointer and XXXRec actual structure) is very common.
Examine the documentation and/or header files to see the fields in a PDColorValueRec. It includes further structures which must also be filled in.
Further key information you need: (1) in PDF, there are 11 colour spaces such as (but not exactly) RGB, CMYK, Lab. For a colour to have meaning you need to give the space. (2) You may be used to colour value in the range 0 to 255, but that is NOT the rule for PDF. For RGB and most other colours they are floating point values (or equivalent ASFixed) in the range 0.0 to 1.0 (3) convert by dividing by 255.
Please have a go and show us your code, so that we can correct if necessary and help you to an understanding of the documentation. I will never write lines of code in reply to a question.
Copy link to clipboard
Copied
Thanks for your instruction, please see following code which pass the compiling, but the color of the annotation still not change.
AVDoc avDoc = AVAppGetActiveDoc(); | |
PDDoc myPDDoc = AVDocGetPDDoc(avDoc); | |
//Create an ASPage object | |
PDPage page = NULL; | |
page = PDDocAcquirePage(myPDDoc, 0); | |
PDColorValueRec colorRec; | |
colorRec.space=PDDeviceRGB; | |
//memset(&colorRec, 0x00, sizeof(colorRec)); | |
colorRec.value[0]=200; | |
colorRec.value[1]=0; | |
colorRec.value[2]=0; | |
colorRec.value[3]=1; | |
PDAnnot annot; | |
char* ptr = "Hello"; | |
//Create an ASFixed object and define its borders | |
ASFixedRect fr; | |
fr.left = ASInt32ToFixed(36); | |
fr.top = ASInt32ToFixed(792-36); | |
fr.right = ASInt32ToFixed(136); | |
fr.bottom = ASInt32ToFixed(792-136); | |
annot = PDPageGetAnnot(page,0); | |
//Create a PDAnnot object | |
annot = PDPageCreateAnnot (page, ASAtomFromString("FreeText"),&fr); | |
//Cast the PDAnnot object to a PDTextAnnot object | |
//textannot = CastToPDTextAnnot(annot); | |
//Open the annotation, set the text, and add it to a page | |
PDTextAnnotSetOpen (annot, true); | |
PDAnnotSetColor(annot,&colorRec); | |
//PDAnnotSetColor(textannot,&colorRec); | |
PDTextAnnotSetContents (annot, ptr, strlen (ptr)); | |
PDPageAddAnnot(page,-2, annot); |
Copy link to clipboard
Copied
you have set the color value to 200. As I noted the range is 0.0-1.0
Copy link to clipboard
Copied
Thanks. Actually, I have tested with value of 0.5 at the beginning, but no effect, so I change back 200. After your instruction, I set to 0.5 again, but still no use. Could you please spend a little time to look into my rest code and find the solution for me? And I want to add red annotation without the border, is this a correct method to create a real Free text annotation? If I defined the &fr, and there must be a border. Sorry, since the API developer examples are too few, I can not find many useful resource.
Copy link to clipboard
Copied
What do you mean by “red annotation”? Text is red? Border is red? Background is red?
Copy link to clipboard
Copied
Only text and border are red, background is transparent. Do you have any good idea?
Copy link to clipboard
Copied
Color Values are ASFixed, I believe. Please check. If they are, you must convert the value to ASFixed from the floating point constant.
You typically need knowledge of the PDF spec to go beyond the basics in the API. This is part of the SDK, though its 1000 pages can be daunting.
Copy link to clipboard
Copied
I suggest you correct the colour values as I suggested.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now