How to move position of annotation text?

I’m using the annotation API to add annotations of type TEXT_FREE.

Is there a way to move the annotation text? By default its above the top-right of the rect.

I’ve tried changing these attributes:

  • position
  • verticies
  • startPoint/endPoint

but the text still doesn’t move.

Thanks,

Okay I was hoping I could do this using the Annoitation.set API with :

mupdf.annotation.set({annotations:[{oid:30, pageIndex:0, rect: {top:20,bottom:40, left: 10, right:30}}]}).then(
    function success(data) {
        console.log("Annotation set successfully");
    },
    function failure(error) {
        console.error(`Error setting annotation: ${error}`);
    }
);

However the code always falls into the failure callback here ( I am sure about my annoataion OID & pageIndex here too), e.g. if I do:

mupdf.annotation.remove({annotations:[{oid:30, pageIndex:0}]}).then(
function success(data) {
console.log(“Annotation removed successfully”);
},
function failure(error) {
console.error(Error removing annotation: ${error});
}
);


then it will remove the annotation as expected.

I have logged a bug with the core developers so please watch this space.

Sorry, that’s not quite what I mean. I don’t mean moving the annotation itself.

Rather changing the default position of the text.

For example in this screenshot, I’ve added an annotation with contents id_18XJKR, i’ve also given it a red stroke colour.

I would like for the annotation contents to appear in the middle of the rect, instead of above the annotation itself.

@39rc Unfortunately I think this is another bug. I believe the annotation should at the very least fit into the top left of the defined rect, not outside it.

I can get a better result by adding a newline to the annotation contents, however it feels like a bit of a hack, like this:

const addAnnot = () => {

        let textRect = { top: 180, bottom: 200, left: 270, right: 405 };

        _mupdf.annotation.add({annotations:[
            {
                type: "TEXT_FREE",
                pageIndex: 0,
                rect: textRect,
                opacity: 1,
                rotation: 0,
                fontFamily:"Helv",
                textAlign:"CENTER",
                author: "Jane Doe",
                contents: "\nHello from WebViewer",
                fillColor: "#00ff00"
            }
        ]
        }).then(
            function successCallbackAdd(data) {
                console.log("Annot added successfully");
            },
            function failureCallbackAdd(error) {
                console.error(`Error adding annotation: ${error}`);
            }
        );
    };


Note, the \n character which forces the text down into the rect.

Without \n:

With \n:

I will log another bug report to see how to improve this.

1 Like