Pymupdf: Question / Comment: Wrong annotation colors on the PDF file

Created on 20 Aug 2020  路  4Comments  路  Source: pymupdf/PyMuPDF

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?

question

Most helpful comment

Uff, bin erleichtert!
O es "qu茅 alivio" mejor?

All 4 comments

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! 馃槃

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Harshil783 picture Harshil783  路  4Comments

shredderzwj picture shredderzwj  路  4Comments

hbh112233abc picture hbh112233abc  路  4Comments

suvinks picture suvinks  路  5Comments

Matmaus picture Matmaus  路  3Comments