Hi,
I'm developing a web application where the user uploads a PDF document, I add some annotations to it and then the user downloads the annotated version. I add basically 2 types of annotations to the PDF text:
1) Regular highlights
2) Underline annotations with an external link
I'm using the page.searchFor() method to get the rects containing the text, then, I check in which of the 2 previous categories the text belongs to and add the corresponding annotation. My code for this part is essentially the following:
rects_list = page.searchFor(text)
for rect in rects_list:
if category == 1:
annot = page.addUnderlineAnnot(rect)
annot.setColors({"stroke": [0, 0, 0.7]})
page.insertLink(
{
"kind": 2,
"from": rect,
"uri": 'insert_text_external_url_here',
}
)
else:
annot = page.addHighlightAnnot(rect)
annot.setColors({"stroke": [1, 1, 0.867]})
Everything seems to be working fine except for the annotation colors in the final PDF, depending on where I open the resulting PDF file.
The colors are correct if I open the PDF on Preview (Mac) or Safari, but if I open it on Adobe Acrobat or Google Chrome, the annotation colors are wrong (one of them is a strong yellow and one is green).
It is really important to me that the colors in the final PDF are correct. I'm not sure what's going on here, if it is something with PyMuPDF or with the rest of my code, as this is part of a web app and the issue is with the downloaded PDF file.
Do you have some thoughts about what might be the problem?
You do an annot.update() after those changes do you?
Have an example PDF for me? I would like to try with one of the various viewers I am working with.
Hi @JorjMcKie, thank you very much for the quick reply!
No, I didn't do an annot.update() after setting the colors and apparently that was the issue :)
Uff, bin erleichtert!
O es "qu茅 alivio" mejor?
Que al铆vio! 馃槃
Most helpful comment
Uff, bin erleichtert!
O es "qu茅 alivio" mejor?