4

I am having difficulties to export a PDF from QGIS 3.4 (having the same issue in 3.12 though) print layout with a clickable hyperlink. Looking at https://docs.qgis.org/2.8/en/docs/user_manual/print_composer/print_composer.html (The label item -> main properties) this should be possible since QGIS 2.8.

Labels can be interpreted as HTML code: check checkbox Render as HTML. You can now insert a URL, a clickable image that links to a web page or something more complex.

I simply want to add a text box below my map including a clickable hyperlink controlled by atlas. I added <a href="link">Click me</a> and set the label box as "Render as HTML". I also tried to achieve this by adding a HTML Frame instead of a text box, but still no luck.

The text/link is not clickable when opening the PDF in Adobe Acrobat or other software. During the export I tried both options: Text export as path and as object. Also I tried to force the export as vector. What am I missing?

This related question was asked before the release of QGIS 2.8 and the accepted answer is outdated as well.

This is how the attributes look like: enter image description here

enter image description here

enter image description here

1 Answer 1

1

Update 2:

As you can notice, only the actual link (URL) of the blue highlighted text actually works as a link; the text before that ("this is a link") does not.

I saved the created QGIS project dummy_atlas together with the polygon-layer as Geopackage for you - than you can try how this works on your computer. Also the pdf-Atlas generated from this project is uploaded as well - find all the files here: https://drive.switch.ch/index.php/s/SDw7YIyjbpxclDs

enter image description here

So as a conclusion (see comments below): this is a link is not clickable, but the part with the url is. Clickable hyperlinks in pdfs seem to be possible in QGIS right now only for the URL-part, not for other texts.

Update 1:

You should be able to use both versions, see screenshot:

Version 1: <a href="[% "link" %]">Click me</a>

Version 2: <a href=[% "link" %]>Cick Me</a><br>

enter image description here

In my case, it works. See the dummy-atlas I exported in pdf here: https://drive.switch.ch/index.php/s/lJp5OlR4pyOoQfs

If you open the pdf in your default pdf-viewer (SumatraPDF in my case), both links work perfectly - not if the pdf is shown in Firefox. Test my pdf and tell if the links work. If not, it means it could be a problem in your pdf-viewer. If it works: are you sure you have set the atlas-configuration correctly (see screenshots):

enter image description here

enter image description here

In my case, the final slash / in the URL created a problem, so I changed the links in the attribute-table from http://www.url.org/ to http://www.url.org

But this seems to be another problem, not connected to your problem.


Original answer:

The correct syntax is:

<a href="[% "AttributeFieldContainingHyperlink" %]">Click me</a>

You can use the expression editor, available below the text-field to automatically generate the correct syntax, selecting there the field from your layer under fields and values.

You should see your links highlighted (blue, underlined, the typical hyperlink-style) in the print composer.

10
  • They are highlighted as links, but unfortunately they are still not clickable. Also when trying other software than Adobe Acrobat to open the pdf.
    – MrXsquared
    May 9, 2020 at 19:38
  • can you share a screenshot, including the text in the label as well as the "code" you use to define the link?
    – Babel
    May 9, 2020 at 20:06
  • Yes, that's what I meant. Second example looks good, in the first one, there are missing quotation marks before and after [ ]. What if you export this atlas - the second link does not work? How does the relevant part of your pdf look like?
    – Babel
    May 9, 2020 at 20:23
  • So the text appears styled as a link but does not react like that. However, below you have "active link" and there, the link seems to work. How did you realize that?
    – Babel
    May 9, 2020 at 20:33
  • Updated my answer, see above: do the links in my pdf work on your machine?
    – Babel
    May 10, 2020 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.