Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Image is visible after converting text to .pdf file
Forum Update on Monday, May 27th 2025

Image is visible after converting text to .pdf file

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 2 Posters 646 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UG SEP
    wrote on 8 Jul 2021, 08:18 last edited by UG SEP 7 Aug 2021, 08:35
    #1

    Hey,
    When I convert my document to a .pdf file the image is not visible but a table, text(bold color ), etc are exported perfectly.
    Here is the piece of code which converts to .pdf

     QTextDocument document;
            document.setHtml(ui->textEdit->toHtml());
    
            QPrinter printer(QPrinter::PrinterResolution);
            printer.setOutputFormat(QPrinter::PdfFormat);
            printer.setPageSize(QPageSize(QPageSize::A4));
            printer.setOutputFileName(fileName);
            printer.setPageMargins(QMarginsF(15, 15, 15, 15));
            document.print(&printer);
    

    First Page

    Here is the exported .pdf file:
    proof.jpg

    Second Page

    proof.jpg

    Edit: Unfortunately I write the title opposite of my problem

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 8 Jul 2021, 09:12 last edited by mrjj 7 Aug 2021, 09:14
      #2

      Hi
      So when you print your QTextDocument to PDF, the image is no shown at all ?

      I would try to look at the HTML from ui->textEdit->toHtml()

      and see how it references the images. IF you didn't use resources for the image, it might not address the image right. and hence it "falls" off.

      But why do you convert to HTML at all ?

      You can ask TextEdit directly for its QTextDocument so not sure why you create a new doc ?

      1 Reply Last reply
      0
      • U Offline
        U Offline
        UG SEP
        wrote on 8 Jul 2021, 16:45 last edited by UG SEP 7 Aug 2021, 17:21
        #3

        Ok,
        I have used tohtml here because i want the textformat in the .pdf file

        M 1 Reply Last reply 8 Jul 2021, 19:24
        0
        • U UG SEP
          8 Jul 2021, 16:45

          Ok,
          I have used tohtml here because i want the textformat in the .pdf file

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 8 Jul 2021, 19:24 last edited by
          #4

          @UG-SEP
          Im not sure what you mean by

          • I have used tohtml here because i want the textformat in the .pdf file

          Im not sure why not
          just
          textedit->document()->print(&printer);

          is not what you are after ?

          https://doc.qt.io/qt-5/qtextedit.html#document-prop

          1 Reply Last reply
          1
          • U Offline
            U Offline
            UG SEP
            wrote on 9 Jul 2021, 06:15 last edited by UG SEP 7 Sept 2021, 06:15
            #5

            Ok let me explain to you,
            I wanted to convert into HTML because if I simply convert text edit so It will not accept the color, font, list, used in the TextEdit so to export them also I have to use toHtml
            there
            May you understand

            M 1 Reply Last reply 9 Jul 2021, 07:06
            0
            • U UG SEP
              9 Jul 2021, 06:15

              Ok let me explain to you,
              I wanted to convert into HTML because if I simply convert text edit so It will not accept the color, font, list, used in the TextEdit so to export them also I have to use toHtml
              there
              May you understand

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 9 Jul 2021, 07:06 last edited by
              #6

              @UG-SEP

              Ah. Yes I understand what you mean.
              Like you want none of the visual formatting.

              But won't some of it still show since you use HTML and HTML can also have font and bold etc ?

              In any case. you should inspect how the image refs are in the HTML.
              Since the images cannot be embedded, it's important how the images are referenced.

              U 1 Reply Last reply 9 Jul 2021, 11:01
              0
              • M mrjj
                9 Jul 2021, 07:06

                @UG-SEP

                Ah. Yes I understand what you mean.
                Like you want none of the visual formatting.

                But won't some of it still show since you use HTML and HTML can also have font and bold etc ?

                In any case. you should inspect how the image refs are in the HTML.
                Since the images cannot be embedded, it's important how the images are referenced.

                U Offline
                U Offline
                UG SEP
                wrote on 9 Jul 2021, 11:01 last edited by
                #7

                @mrjj so what should I do so image can be visible in .pdf

                M 1 Reply Last reply 9 Jul 2021, 11:09
                0
                • U UG SEP
                  9 Jul 2021, 11:01

                  @mrjj so what should I do so image can be visible in .pdf

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 9 Jul 2021, 11:09 last edited by
                  #8

                  @UG-SEP

                  First find out why its not shown.

                  So look in the HTML you get from
                  toHtml()

                  and see how the IMG ref tag is written.

                  It can be its relative path or something that won't work.

                  How do you insert the image in the first place ?
                  Is it in a resource or do you point to a file some place on your hard drive?

                  1 Reply Last reply
                  0
                  • U Offline
                    U Offline
                    UG SEP
                    wrote on 10 Jul 2021, 06:21 last edited by
                    #9

                    no it is not in resource

                    1 Reply Last reply
                    0

                    2/9

                    8 Jul 2021, 09:12

                    topic:navigator.unread, 7
                    • Login

                    • Login or register to search.
                    2 out of 9
                    • First post
                      2/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved