go-fitz icon indicating copy to clipboard operation
go-fitz copied to clipboard

doc.Image() does not render annotations

Open sanderjson opened this issue 9 months ago • 5 comments
trafficstars

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?

sanderjson avatar Feb 12 '25 19:02 sanderjson

The whole APi is in docs, so there are no hidden options. Check mupdf documentation and return back with your findings about highlights.

gen2brain avatar Feb 13 '25 11:02 gen2brain

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

jzillmann avatar May 05 '25 23:05 jzillmann

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.

gen2brain avatar May 06 '25 01:05 gen2brain

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 ?

jzillmann avatar May 06 '25 13:05 jzillmann

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

SCUTJoeham avatar May 10 '25 13:05 SCUTJoeham