pdf-generationadobepdfiumpdf-annotations

Difference between FPDFAnnot_SetRect and FPDFAnnot_AppendAttachmentPoints when adding a annotation to pdf document


I'm using pdfium to add annotations to pdf files. I opened the pdf file using Notepad++ and viewed its objects. Annotation object was present inside the Page object as follows,

3 0 obj
<</Annots[<</C[ 1 1 0]/CA 1/F 4/QuadPoints[ 0 300 300 300 0 0 300 0]/Rect[ 216.182 702.94 368.75 686.38]/Subtype/Highlight/Type/Annot>>]/Contents 4 0 R /Group<</CS/DeviceRGB/S/Transparency/Type/Group>>/MediaBox[ 0 0 612 792]/Parent 2 0 R /Resources<</ExtGState<</GS7 7 0 R /GS8 8 0 R >>/Font<</F1 5 0 R >>/ProcSet[/PDF/Text/ImageB/ImageC/ImageI]>>/StructParents 0/Tabs/S/Type/Page>>
endobj

I used following code to add the rect and attachment points to the annotation.

FPDF_ANNOTATION highlightAnnot = FPDFPage_CreateAnnot(page, FPDF_ANNOT_HIGHLIGHT);
FPDFAnnot_SetRect(highlightAnnot, &rect);
FPDFAnnot_AppendAttachmentPoints(highlightAnnot, &new_quadpoints);

As I understood, Attachment points are set to give the location of Highlight annotation where we want it to be. But I don't understand the purpose of setting the Rect for this annotation.

Can someone please tell the reason for using FPDFAnnot_SetRect function?

Another thing,


Solution

  • FPDFAnnot_SetRect defines the bounding box, while FPDFAnnot_AppendAttachmentPoints defines the actual shape. Consider a multiline highlight annotation, it has only one Rect, but several AttachmentPoints.

    A Rect could be used as a "collision box" at application level so that when you click on it, you select the contained annotation. Or it can be an "updating box".

    Rect is more general and only text-related annotation types have AttachmentPoints.