0

I'm using Vala for Webkit (webkit2gtk-4.0) to display HTML content on WebView. Instead of showing the vertical scrollbars, I would like to break up the page into a smalled set of lines i.e. pagination. the attached picture will give an idea of the content i'm displaying.enter image description here

Is there someway I can identify the number of lines when the content reaches the max page size and break up the content into the next page and so on. Is there a signal I can connect to which will help me do pagination. Here is the link to my code on GitHub: bookworm

The content has its own stylesheets and also images, so I cannot think of characters per line and no of lines per page to do the pagination.

Thanks in advance for any ideas.

Siddhartha Das
  • 251
  • 1
  • 8
  • Do it in JavaScript; a very quick search turned up http://stackoverflow.com/questions/12202324/split-text-into-pages-and-present-separately-html5#12205201 and I'm sure there are many other alternatives. – nemequ Feb 08 '17 at 17:35
  • 2
    Or, better yet, don't do it at all. Page numbers would depend on how the content is rendered, so if people are using it to remember what page they're on they'll be in for a surprise if they move to another device, change the window size, change their fonts, etc. If you want buttons instead of a scrollbar, maybe just "next page" and "previous page" button which inject a pageup/pagedown event (or alter the window by a bit less than the viewport size, see https://andylangton.co.uk/blog/development/get-viewportwindow-size-width-and-height-javascript). – nemequ Feb 08 '17 at 17:36
  • Nemequ- Many thanks for your suggestions. I like the second idea. need to figure out how to reach let's say the fourth page down on a certain page where the user left off earlier... – Siddhartha Das Feb 12 '17 at 09:45
  • Any ideas of how to remove the scroll bar from the webview and add buttons which do next and previous page to inject page up and page down...will help if you can point me to any api or sample code... – Siddhartha Das Feb 20 '17 at 11:44
  • Easiest way would be to use `Gtk.ScrolledWindow.set_vadjustment` to move the page. If you really need to inject a pageup/down keypress you would need to create a `Gdk.EventKey` then use `Gdk.Event.put` to inject it. For hiding the scrollbars, you want `Gtk.ScrolledWindow.set_policy`. – nemequ Feb 20 '17 at 17:02
  • Looks like in WebKit2 (which I'm using) the access to the scrollbar which webview automatically adds is quite difficult(webkit extension), will see if wrapping the webview in a ScrolledWindow gives me control of the scrollbar, otherwise javascript might be the way forward: http://stackoverflow.com/questions/21781868/scrolling-a-webkit2-webkit-window-in-gtk3 – Siddhartha Das Feb 24 '17 at 09:03

0 Answers0