Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html formatted text boxes do not create links in pdf outputs #19117

Closed
qgib opened this issue Jun 26, 2014 · 16 comments
Closed

html formatted text boxes do not create links in pdf outputs #19117

qgib opened this issue Jun 26, 2014 · 16 comments
Labels
Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks

Comments

@qgib
Copy link
Contributor

qgib commented Jun 26, 2014

Author Name: Giovanni Manghi (@gioman)
Original Redmine Issue: 10731

Redmine category:map_composer/printing


Not sure if this is a feature request or a bug,

if I create a text box in a composer and add a tag

link

when outputting to PDF the link text is formatted as expected (blue, underlined), but the link does not work (maybe it does not exist as it is not clickable).

It does not depend on the platform (tested Linux and Windows) and also does not depend on how the PDF is created (the QGIS function or other virtual printer).

@qgib
Copy link
Contributor Author

qgib commented Sep 11, 2014

Author Name: Regis Haubourg (@haubourg)


Hi,
it seems there was a bug in QT 4.7 , solved in 4.8.. I guess we just have to wire that feature:
see [[http://stackoverflow.com/questions/24163671/wicked-pdf-export-html-links-as-plain-text]]

cheers
Régis

@qgib
Copy link
Contributor Author

qgib commented Sep 29, 2015

Author Name: Nyall Dawson (@nyalldawson)


  • assigned_to_id removed Nyall Dawson

@qgib
Copy link
Contributor Author

qgib commented Mar 18, 2016

Author Name: Patrick Valsecchi (Patrick Valsecchi)


I doubt this is a bug fixed in Qt 4.7. The link in the previous comment points to post about wicked, not Qt and QGIS uses Qt to render PDFs.

This bug has been fixed in Qt5.6:
qt/qtwebkit@62dd2ad

Therefore we'll have to wait for the port to Qt5 to be done and we'll be able to close this issue.

@qgib
Copy link
Contributor Author

qgib commented Apr 30, 2017

Author Name: Giovanni Manghi (@gioman)


  • easy_fix was configured as 0

@qgib
Copy link
Contributor Author

qgib commented Sep 4, 2018

Author Name: Alain FERRATON (@FERRATON)


it seems that the bug still exists in QGIS 3.3 master which uses Qt 5.9.2

@qgib
Copy link
Contributor Author

qgib commented Sep 4, 2018

Author Name: Giovanni Manghi (@gioman)


Alain FERRATON wrote:

it seems that the bug still exists in QGIS 3.3 master which uses Qt 5.9.2

unfortunately I confirm.


  • description was changed from Not sure if this is a feature request or a bug,

if I create a text box in a composer and add a tag

link

when outputting to PDF the link text is formatted as expected (blue, underlined), but the link does not work (maybe it does not exist as it is not clickable).

It does not depend on the platform (tested Linux and Windows) and also does not depend on how the PDF is created (the QGIS function or other virtual printer).
to Not sure if this is a feature request or a bug,

if I create a text box in a composer and add a tag

link

when outputting to PDF the link text is formatted as expected (blue, underlined), but the link does not work (maybe it does not exist as it is not clickable).

It does not depend on the platform (tested Linux and Windows) and also does not depend on how the PDF is created (the QGIS function or other virtual printer).

@qgib qgib added Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks labels May 25, 2019
@suricactus
Copy link
Contributor

5.12 and current master still have the same issue, QT 5.12.4.

@ThomasG77
Copy link
Contributor

ThomasG77 commented Apr 3, 2020

Not sure how it works on QGIS side but I'm able with pure PyQt to export a simple PDF with link using a QPrinter and QPainter e.g https://gist.github.com/ThomasG77/72fd711bda2ec0c8b95a0dacd2dbb942 (QGIS build with Qt 5.9.5)

From what I've seen so far, QgsLayoutExporter::exportToPdf (https://qgis.org/api/qgslayoutexporter_8cpp_source.html#l00507) calls QgsLayoutExporter::printPrivate (https://qgis.org/api/qgslayoutexporter_8cpp_source.html#l01206) with QPainter and QPrinter among the args.
This function calls QgsLayoutExporter::renderPage (https://qgis.org/api/qgslayoutexporter_8cpp_source.html#l00154) that call QgsLayoutExporter::renderRegion (https://qgis.org/api/qgslayoutexporter_8cpp_source.html#l00244). It calls a the painter as an arg and then make a call to render QgsLayout to painter using inherited function render from QGraphicsScene(https://doc.qt.io/qt-5/qgraphicsscene.html#render). Although I've started tracking in the code how PDF rendering happens, I'm always unable to confirm where exactly the issue happens. Need more investigation. Looking for others input.

@signedav
Copy link
Contributor

signedav commented Nov 2, 2021

@ThomasG77 Have you done any more investigations, or is this the status to pick up?

@ThomasG77
Copy link
Contributor

@signedav Did not have time to investigate more. After all, not a low level dev, difficult for me to go further.

@m-kuhn
Copy link
Member

m-kuhn commented Nov 16, 2021

Some further analysis on this.

The Qt printing API does not allow generating links through public API.

What existing Qt classes use to deal with this:

  • QTextDocument uses a purely internal, private implementation (QTextItemInt) which is understood by the pdf exporter code
  • QWebView uses a dedicated printing function which very likely cannot easily be mixed with other generic painting code (like QGraphicsScene)

A first proof of concept shows, that with QTextDocument it is possible to add links within an ongoing printing process by directly using the layout.draw() function.

Implementing this in QGIS should be possible.
The limitations of this are:

  1. Only a subset of HTML is supported: https://doc.qt.io/qt-5/richtext-html-subset.html . It should therefore be added as a new option for HTML items (export labels at the expense of supporting a limited set of HTML)
  2. The link is also clickable if it is outside the clipped region. Might be solvable.
Sample code that mixes QGraphicsScene and QTextDocument
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtPrintSupport import *
from PyQt5.Qt import *

app = QApplication([])
doc = QTextDocument()
doc.setHtml('<a href="http://qfield.org/get"> go get it</a>')
layout = doc.documentLayout()

printer = QPrinter()
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName("/tmp/output.pdf")

scene = QGraphicsScene()
scene.addRect(100, 0, 20, 100, QPen(Qt.black), QBrush(Qt.green))

painter = QPainter(printer)
scene.render(painter)
ctx = QAbstractTextDocumentLayout.PaintContext()
painter.save()
painter.setClipRect(QRectF(50, 50, 100, 100))
painter.translate(QPoint(100, 100))
layout.draw(painter, ctx)
painter.restore()
painter.end()

@nirvn
Copy link
Contributor

nirvn commented Jan 26, 2024

Unless I'm missing part of the intent of the author who filed this issue, this has been implemented in QGIS already.

@ThomasG77
Copy link
Contributor

ThomasG77 commented Jan 26, 2024

Not really except if I'm using an old QGIS version. See the project attachment (debug_export_pdf.zip). Export to pdf the layout (also attached Mise en page 1.pdf) and see that the content although blue does not behave as a link. You can click as much as you want when using the generated PDF with a PDF viewer: nothing happens or at least for me.

@signedav
Copy link
Contributor

signedav commented Jan 26, 2024

What version you are using @ThomasG77 ? afaik it should work since 3.32

@ThomasG77
Copy link
Contributor

ThomasG77 commented Jan 26, 2024

Don't ask... Too old 3.28 (not the latest of the serie). If it works on more recent versions and you can confirm, close as suggested by @nirvn (my error here if fixed but only in recent versions)

@nirvn
Copy link
Contributor

nirvn commented Jan 27, 2024

@nirvn nirvn closed this as completed Jan 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Request Print Layouts Related to QGIS Print Layouts, Atlas or Reporting frameworks
Projects
None yet
Development

No branches or pull requests

6 participants