Hi,
I’m trying to use the redaction API in the webviewer but i’m having some confusion.
In the docs, set’s api is defined as follows:
set(config: { redactions: Redaction[] }).
However, when I go to run this function I get these errors:
InvalidArgumentError: Unrecognized key(s) in object: 'oid'
set mupdf.js:1
Blah Blah.tsx:168
React 7
There’s this line in the Redaction documentation:
You need to set oid or name and pageIndex as the unique key. Then the property will be updated.
Which implies I can remove oid? Not sure if this is the correct interpretation or not.
But the typescript for set is defined as follows:
set(config: {
redactions: {
oid: number;
pageIndex: number;
name: string;
rect?: TRect;
opacity?: number;
author?: string;
canBePrinted?: boolean;
locked?: boolean;
}[];
}): Promise<undefined>;
So oid, pageIndex and name must be defined on the object. I can’t find any more information on ‘setting the unique key’.
I’m assuming a redaction must be exist for me to set it after right?
Just in case I’m running into an xy problem, I’ve got a react application where I’m trying to set up the webviewer to save redactions to a server and load them back when the document is loaded again.
Ideally, I would like some sort of 2 way sync between webviewer’s internal state and the server’s state.
Where the code would look something like this
// initMuPDFWebViewer is loaded into react state, on page load in a useEffect
const serverState = bunchOfRedactions // this is a prop containing the redactions from the server
const updateServerState = (redactions) => {
// upload changes to the server
}
useEffect(() => {
// This should listen to mupdf's internal state and update the server's state accordingly
mupdf.addEventListener(
mupdf.refs.event.type.REDACTION_DO_STUFF,
updateServerState
)
// When this event listener gets called, the server state should be updated,
// In turn the 'serverState' should be updated and the useEffect below should be called
return () => {
//clean up event listener
}
}, [deps])
useEffect(() => {
// This should listen to any changes to serverState and update mupdf's interal state accordingly
if (isFirstLoad) {
mupdf.redaction.add({ redactions: serverState });
setIsFirstLoad(false);
} else {
mupdf.redaction.set({ redactions: redactions });
}
return () => {
// clean up mupdf's internal state
}
}, [serverState])
I’d appreciate any help with this.
Thanks