Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

PDF with Table of Contents/Bookmarks?



  • Hi everyone,

    We're using Qt 5.6.1 (soon to be 5.12.1) for a large C++ Windows/Mac application. In our app, we give users the ability to export their data to a PDF. We're currently using a 3rd party library to achieve this, but we'd like to use native Qt if possible moving forward. However, due to the size of the data we export, navigating around the document is crucial (for a large user file, we're looking at ~14K pages in the export).

    Is there currently a way to create a table of contents/bookmarks via a generated PDF in Qt 5.6.1/5.12.1? If so, what would be the best way to set this up? If not, are there any plans in the future to add this feature?

    A few limitations we are under:

    • We can't use Chromium since we support WinXP still (so WebEngine is a problem)
    • We're only interested in exporting to PDF - reading it isn't a requirement for us

    Thank you in advance!


  • Qt Champions 2019

    @TheRedQueen To my knowledge you can only export to PDF in Qt using QPrinter, see https://wiki.qt.io/Handling_PDF



  • @jsulm , @TheRedQueen
    It depends on what you mean by "printer", but since that wiki was written there is now (Qt 5.something, maybe wiki could do with updating) https://doc.qt.io/qt-5/qpdfwriter.html. That would be in addition to existing methods (a) via QPrinter.PdfFormat and (b) via QWebEngine, but it's still intended for a "painting device".

    At any rate, none of these is going to generate anything like an index. You might intercept the PDF being generated for this, or you might post-process the PDF output file, but you're liable to still want a third-party library....


  • Lifetime Qt Champion

    Hi,

    Are you looking for QPdfWriter ?


  • Lifetime Qt Champion

    Hi
    As far as i know, QPdfWriter can't create bookmarks.
    however, the Jonas poster there seems to have added it.
    https://bugreports.qt.io/browse/QTBUG-3893
    in
    https://bitbucket.org/jonaslarsson/qextpdfwriter/src
    However, its somewhat old, so might not be good enough for newest Qt.



  • @mrjj , @SGaist
    Good one, didn't know about that patch-addition. It says

    Hope to see PDF outlines feature added to official Qt.

    because I only know it's not in existing QPdfWriter documentation.

    Let me get one thing clear: for PDF my code used to use QPrinter, now it uses QWebEnginePage::printToPdf(). I do not use QPdfWriter (at least not explicitly). I have asked before what, if any, is the relationship in the PDF generation between these 3 classes? Does the code/patch for TOC etc. mean that if I wish to avail myself of it I will need to change over to QPdfWriter, it will not be available from the other two classes? Thanks.


Log in to reply