Results 1 to 9 of 9

Thread: How to work with internal anchors

  1. #1
    Join Date
    Oct 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default How to work with internal anchors

    Hello,

    in my project documentation is important. I use QPrinter and QTextDocument to save the data into a pdf. Everything works fine so far (ok, not everything, I struggle with putting a watermark on every side, but that's not half as important as the question, I start this Thread about), except that I don't become internal links working.

    I write HTML into a QByteArray and import that via setHtml into the QTextDocument (the style-stuff goes in via a separate QByteArray and setDefaultStyleSheet). Anchors are set with <a name='target'>, internal links are set with <a href='#target'>. Nothing special so far.

    But in the pdf there are no internal links. The tooltip shows, that the path to the document is always preceding the '#target'. All links are external. Maybe that would be ok, but after the drive-letter the ':' seems to be corrupted. There is a narrow black block instead. The link simply doesn't work.

    Is there a 'open Sesame' that I can use to get internal links working?

    Thanks

    MDCremer

  2. #2
    Join Date
    Oct 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to work with internal anchors

    Hello again,

    ok, there are a few possibilities:
    - my English is too bad and nobody understands me (I know, it's bad),
    - the problem is harder than I thought,
    - I missed to give a proper example.

    At least the last point can be fixed:

    Qt Code:
    1. text.append("<a name='title'>title</a><br><br><br><a href='#title'>Go to title!</a>\n");
    2. output.setHtml(text);
    3. output.print(&qprinter); // generates the PDF
    To copy to clipboard, switch view to plain text mode 

    As you can see on the screenshot, the link is transformed. Instead of targeting to the internal anchor, there should be loaded a file 'title' in the local directory.

    I use Qt5.5 on Windows 10.

    Is there a way that I can use links targeting within a pdf?

    Attachment 11417

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to work with internal anchors

    Maybe that is currently not supported by Qt's PDF generator.

    Have you tried both options?
    1) QPrinter with an output file
    2) QPdfWriter

    Cheers,
    _

  4. #4
    Join Date
    Oct 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to work with internal anchors

    Hello anda-skoa,

    as far as I have understood, the concept of QPdfWriter is to be a paint-device. The documentation I've in mind is a several hundred pages strong document, the printout of a whole database, some sort of a lexicon. That's what I need internal links for, to jump from one part of the lexicon to another. Maybe because I worked several decades with LaTeX, painting one page after another isn't what I want (I dont work with LaTeX in this project, because Qt has a subset of HTML for richtext. That's fine. I only have to become the whole stuff into a pdf).

    If there is no way using Qt to accomplish such a task, are there other c++-libraries out there? I switched with my project from .Net to Qt. On .Net I worked with iTextSharp. Is there a similar product (free) for c++ on the market?

    Thanks
    Last edited by MDCremer; 11th October 2015 at 12:04.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to work with internal anchors

    Quote Originally Posted by MDCremer View Post
    as far as I have understood, the concept of QPdfWriter is to be a paint-device.
    Yes, like QPrinter.
    It is likely using the same PDF generator, but you won't know for sure until you try.
    Hence me asking whether you have already tried.



    Quote Originally Posted by MDCremer View Post
    If there is no way using Qt to accomplish such a task, are there other c++-libraries out there?
    Very likely.

    Cheers,
    _

  6. #6
    Join Date
    Oct 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to work with internal anchors

    Hello once more,

    I tested it with QPdfWriter. There is a difference indeed!

    example2.jpg

    You can see, it suggests to reload the document. But if I say to do so, this is the next message:

    example3.jpg

    Unfortunatly, the '#' is escaped. Consequently the next message is:

    example4.jpg

    The Link is gone!

    But I assume that's the fault of the Acrobat Reader and is insofar not covered by this forum.

    Regards

    P.S.: I downloaded a Hex-Viewer and took a look at the generated PDF. Qt produces:

    example5.jpg

    A working example generated by iTextSharp has the format:

    example6.jpg

    As you can see, both links are saved without any reference to the file itself. This is obviously generated by the Acrobat Reader. The difference between the non working Qt example and the other, working example are the spaces (and in the working example there is no 0x0A between the /URI-tags). The spaces in the working example are missing.

    That might be very interesting. But as long as I don't know how to tell Qt to don't use spaces the link will not work, I fear.
    Last edited by MDCremer; 11th October 2015 at 15:11.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to work with internal anchors

    That minor difference could mean that there is a bug in the PDF generator.
    Have you checked the Qt bug database?

    In any case it is good to know that QPdfWriter does indeed do things differently to usng QPrinter in PDF mode.

    Cheers,
    _

  8. #8
    Join Date
    Oct 2015
    Posts
    5
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to work with internal anchors

    Hello anda_skoa,

    I went to the Newbie-Forum with my question, because I'm really very new to Qt. Maybe that I have a little bit experience in programming throughout the years, but I'm really not familiar how to check the Qt bug database (in fact, the first time I hear about that). Where can I find it, how can I add info about the maybe wrong pdf-behavior?

    (I know, spaces are always good for readability of code. But with that particular code only the reader has to do. And obviously the additional spaces don't lead to a higher readability. Besides of that, that's 3 Bytes of wasted memory for every link. I know, memory is cheap nowadays...)

    I'm not too shure about the different behavior of QPdfWriter und QPrinter. As I looked after the PDF's with the Hex-Viewer there where no difference between them. Maybe I forgot the '#' in my first example with QPrinter. That's why the Acrobat Reader wants to open the file. Sorry.

    Regards

  9. #9
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How to work with internal anchors

    Qt's public bug tracker is at https://bugreports.qt.io

    I did a quick search for "PDF links" and this one was the first hit: https://bugreports.qt.io/browse/QTBUG-12035

    Not totally sure this is the same thing though.

    Cheers,
    _

Similar Threads

  1. Mixing anchors and layouts - wise or not?
    By MarkoSan in forum Qt Quick
    Replies: 1
    Last Post: 8th September 2015, 09:56
  2. Animating JS-bound anchors with behavior ?
    By Data42 in forum Qt Quick
    Replies: 0
    Last Post: 22nd January 2014, 18:42
  3. Positioning problem, anchors not allowed
    By kornicameister in forum Qt Quick
    Replies: 0
    Last Post: 26th August 2011, 09:35
  4. QPlainTextEdit and anchors
    By bear101 in forum Qt Programming
    Replies: 2
    Last Post: 13th December 2009, 18:10
  5. Replies: 2
    Last Post: 1st April 2009, 23:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.