Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saving and reapplying annotations inconsistency #2355

Open
DayibBaba opened this issue Jun 3, 2024 · 3 comments
Open

Saving and reapplying annotations inconsistency #2355

DayibBaba opened this issue Jun 3, 2024 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@DayibBaba
Copy link

DayibBaba commented Jun 3, 2024

I use getSerializedAnnotations() to save all annotations to a annotations: EditorAnnotation[] variable. In turn, I save this as a JSON file on my database (firebase storage). After fetching it back and using addEditorAnnotation() to reapply the annotations, they always seem to have moved just a little upwards. All annotations are pasted back and look to be higher in position then beforehand. This is especially noticeable when highlighting a specific line in the document. Looking into the save data and comparing the values does show differences in the coordinates of the annotations. So somewhere in between saving and reapplying, I am getting inconsistent values in a consistent manner (it always moves slightly upwards).

Before reapplication:
image

After:
image

EDIT:
Not saving and simply reapplying seems to work correctly. When an annotation is serialized again, and saved for reapplication, is where the issue seems to occur.

@stephanrauh stephanrauh self-assigned this Jun 3, 2024
@stephanrauh stephanrauh added the nuisance a bug that only shows in the logs; or: a bug with an obvious work-around every user finds quickly label Jun 3, 2024
@DayibBaba
Copy link
Author

@stephanrauh nuisance? Is there a simple work-around in which I can adjust for the apparent offsets that occur within getSerializedAnnotations()?

@stephanrauh stephanrauh added bug Something isn't working and removed nuisance a bug that only shows in the logs; or: a bug with an obvious work-around every user finds quickly labels Jun 3, 2024
@stephanrauh
Copy link
Owner

OK, you're right - it's more than a nuisance. It's not as bad as many other bug because it almost works, but you're right, "almost" isn't good enough.

Your bug rings a bell. Coordinates are notoriously difficult with the annotation API. In particular, I noticed that there seems to be an offset shifting annotations upward - pretty much as you've reported. I assume that simply means I haven't understood the coordinates yet. Adding insult to injury, we're talking about an internal API of pdf.js that may change at any point in time. I hope it doesn't, but it happened in the past.

At the moment, I don't know how to proceed. Can I talk you into helping me? I know that's mean because it's you who's asking me for help, but if I give you some clues how to debug, would you like to do it?

@DayibBaba
Copy link
Author

DayibBaba commented Jun 3, 2024

OK, you're right - it's more than a nuisance. It's not as bad as many other bug because it almost works, but you're right, "almost" isn't good enough.

Your bug rings a bell. Coordinates are notoriously difficult with the annotation API. In particular, I noticed that there seems to be an offset shifting annotations upward - pretty much as you've reported. I assume that simply means I haven't understood the coordinates yet. Adding insult to injury, we're talking about an internal API of pdf.js that may change at any point in time. I hope it doesn't, but it happened in the past.

At the moment, I don't know how to proceed. Can I talk you into helping me? I know that's mean because it's you who's asking me for help, but if I give you some clues how to debug, would you like to do it?

I am in the middle of a project but, maybe I could look into it. I have already cloned your repo to check your code, haven't looked too deep yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants