thank you very much for the help,
I managed to make the highlighting. *do you know how to save the highlights
in the same pdf?*
I tried to use save_annotation() of evincedocument, but I don't know how to
use it. it requires an annotation but get_annotations() gets a mappinglist
type.
any better way?
if you also have some idea regarding adding links it would be great (now I
infer the position of the cursor in the pdf in a complicated way, add the
link using a library like fitz and reload the pdf so it appears in the
evince viewer, no so clean! and not smooth)
thanks

Davide

On Thu, Oct 3, 2019 at 8:50 PM Germán Poo-Caamaño <[email protected]> wrote:

> On Tue, 2019-10-01 at 21:02 +0200, Davide Nitti via evince-list wrote:
> > I'm making a pdf editor in python reusing evince and Gtk libraries.
> >
> > I would like to add a link with a click, but I don't know *how to
> > convert the cursor position I get from the click event to the
> > position and page in the pdf document.*
> >
> > I would also like to *add annotations* (highlights for example), this
> > should be implemented in evince, but I don't know how to import this
> > feature in python.
>
> You might want to start with something simpler, like adding an
> annotation based on the text already selected. Something like the
> design proposal in h
> ttps://wiki.gnome.org/Design/Apps/DocumentViewer#Discussion
>
> To achieve that, you could do something like:
>
> class ...
>     def __init__(...):
>         ...
>
>         self.view.connect('button-event',
>                           self.on_button_release_event)
>         ...
>         box = Gtk.Box()
>         button = Gtk.Button.new_with_mnemonic("_Highlight")
>         button.connect("clicked", self.on_open_clicked)
>         box.pack_start(button, True, True, 0)
>         button.set_border_width(6)
>
>         self.popover = Gtk.Popover()
>         self.popover.add(box)
>         self.popover.set_position(Gtk.PositionType.BOTTOM)
>         self.popover.set_relative_to(self.view)
>         ...
>
>     def on_button_release_event(self, view, event):
>         pos = Gdk.Rectangle()
>         pos.x, pos.y = event.x + 6, event.y + 6
>         pos.width, pos.height = 0, 0
>         if self.view.get_has_selection():
>             self.popover.set_pointing_to(pos)
>             self.popover.show_all()
>             self.popover.popup()
>         else:
>             self.popover.popdown()
>
>     def on_open_clicked(self, button):
>         if self.view.get_has_selection():
>             self.view.add_text_markup_annotation_for_selected_text()
>             self.popover.popdown()
>
> if you want a different type of markup annotation, then you would need
> to set it up to squiggly, StrikeOut, or Underline.
>
> If you want to do it interactively, then you can use:
>
>         self.view.begin_add_annotation(annot_type)
>
> then you can explore the values in EvinceDocument.Annotation*
>
> You can take a look at how is implemented in Evince, for example, in
> https://gitlab.gnome.org/GNOME/evince/blob/master/shell/ev-window.c
>
> search for annotation/annot.
>
> Best,
>
> --
> Germán Poo-Caamaño
> https://calcifer.org/
>
>
>
_______________________________________________
evince-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/evince-list

Reply via email to