go-fitz
go-fitz copied to clipboard
doc.Image() does not render annotations
I have a pdf with highlights but when I convert the pdf to images using doc.Image(n) the images are saved without the highlight. Is there some options I must enable, or is this information (coordinates) available in another function?
The whole APi is in docs, so there are no hidden options. Check mupdf documentation and return back with your findings about highlights.
In the pymupdf documentation (https://pymupdf.readthedocs.io/en/latest/recipes-images.html#how-to-create-or-suppress-annotation-images:~:text=or%20Suppress%20Annotation-,Images,-%23) they are stating that the annotations will be part of the image (pixmap) by default and you can disable that with annots=False.
However, my experience with using fitz is that the images do not contain the annotations (text boxes in my case).
What am i missing ?
Attaching an example PDF. pdfWithAnnotations.pdf
You are referencing the pymupdf docs; those bindings have many options and features that are not even available in the C API (e.g., see issue #86). You need to know how to do that with the C API, or you can reference the pymupdf C code to see how it is done there.
Quite hard for me to figure out which documentation belongs to which language implementation...
https://mupdf.readthedocs.io/en/latest/mutool-object-pdf-annotation.html#run see the run(device, transform) - Calls the device functions to draw the annotation.
Is that for the C-API ? might be https://github.com/ArtifexSoftware/mupdf/blob/master/source/pdf/pdf-run.c ?
I just found out that simply replace C.run_page_contents with C.run_page can fix this issues: https://github.com/gen2brain/go-fitz/blob/f1c7716a999d9e4deb2d470a48eddc36180472f4/fitz_cgo.go#L234