Author Topic: how to add hyperlinks, draw frame around a text  (Read 4059 times)

michaelu

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
  • Scribus User
how to add hyperlinks, draw frame around a text
« on: October 24, 2019, 03:13:36 pm »
A hyperlink can be added to a document e.g. by selecting the PDF-Tool "Link Annotation", with the tool drawing a box around the text that shall be linked, double clicking into the box, choose "External Web-Link", then enter the URL as destination. Can we do this from a script? Apparently it is necessary to draw a frame around the text, then call setURIAnnotation for this frame. So the question seems to be really: Given a textframe and some words in the text, how can I determine the x,y,w,h needed to create the smallest frame in which the words are contained (the bounding box)?

Having the hyperlink associated with a frame instead of with the text is problematic anyhow. Consider what happens if you change the text, e.g. put a newline into it. This is perhaps due to PDF? In this way, adding hyperlinks would have to be the very last thing you do to the document before exporting it.

michaelu

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
  • Scribus User
Re: how to add hyperlinks, draw frame around a text
« Reply #1 on: November 02, 2019, 03:08:59 pm »
The same applies to a line. I cannot draw a line between two paragraphs and expect the line to move, when the first paragraph gets shorter or longer. It seems to me as of now, that it is not possible with Scribus to implement the markdown codes a and hr, to insert a hyperlink or a horizontal ruler. Even if I assume that the text does not change anymore, I can not find out the coordinates where the paragraph ends, after which the line should be drawn, right?

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2418
  • Karma: 35
    • the graphics lab
Re: how to add hyperlinks, draw frame around a text
« Reply #2 on: November 02, 2019, 04:16:25 pm »
hi michael

for the lines, there is a workaround: you can paste a line into a text frame (basically, you can paste anything in a test frame).

i'm not sure if you can insert inline item through the scripter.

in the case of the hr, i would say that a good alternative would be to insert three asterisks

  *
*   *

for the links: i'm also interested in getting them to work in scribus, but it's not an easy task.
if you want to have a look at it, i have a few links to share...
you will need to have a look at the pdf specifications and dig deep into the pdf creation code of scribus.
(well, it's probably not that hard either... but not trivial either)

ciao
a.l.e

michaelu

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
  • Scribus User
Re: how to add hyperlinks, draw frame around a text
« Reply #3 on: November 02, 2019, 08:35:34 pm »
And do you perhaps know of a way, given e.g. a word "here", in a text "click here", to determine the x,y,w,h of a rectangle around the word, if all you know is the position, i.e. character number, of the first letter of the word in the text frame?

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2418
  • Karma: 35
    • the graphics lab
Re: how to add hyperlinks, draw frame around a text
« Reply #4 on: November 02, 2019, 09:57:36 pm »
i think that there is a way to find it out, but it's probably not straight forward.

you will probably have to go through the layout and calculate the position line by line.
putting a trigger in the text layouter that creates a link might be easier than querying the position from outside.

michaelu

  • Newbie
  • *
  • Posts: 15
  • Karma: 0
  • Scribus User
Re: how to add hyperlinks, draw frame around a text
« Reply #5 on: November 06, 2019, 07:56:51 am »
Tables have the same problem: createTable requires also x,y parameters, which you don't know how to determine from a script. But Tables seem to be broken anyhow, in a number of ways. I cannot even ungroup a table in 1.5.6.svn, and sometimes not even select them. Shall I report a bug?

I intend to spend some time soon on hyperlinks, in the way the fpdf-package in python does it. There, you have a funktion cell(text,..[,url]), where the url accompanies the text until the final layout is done (https://github.com/reingart/pyfpdf/blob/master/fpdf/fpdf.py, look for page_links).

a.l.e

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2418
  • Karma: 35
    • the graphics lab
Re: how to add hyperlinks, draw frame around a text
« Reply #6 on: November 06, 2019, 09:19:17 am »
i don't think that it makes sense to submit (further) bug reports for the tables.
except for tickets that could help somebody, who would start working on the tables code.

we need somebody with strong interest in tables to fix the bugs and finish the implementation.

and, no, you're not supposed to ungroup a table (that was an anti-feature in 1.3, because at that time tables were just a bunch of frames grouped together).

on the other side ,research work on hyperlinks is very welcome..