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. In QT, how to add high resolution images to textdocument
QtWS25 Last Chance

In QT, how to add high resolution images to textdocument

Scheduled Pinned Locked Moved Unsolved General and Desktop
word
7 Posts 2 Posters 1.6k 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.
  • S Offline
    S Offline
    sachinrd
    wrote on 2 Aug 2020, 07:37 last edited by
    #1

    I am generating a word document report in qt. I want to insert a high resolution image to qtextdocument. The textdocumnet is written into odt format using textdocument writer.Below listed is my problem W.R.T generating the report:

    • inserting high resolution images results in only a small part of image getting displayed in the resulting word document.
    • how to have multiple pages in the word doc with each page having its own size. I am stuck with this from days.. Any help will be helfull.Thanks.

    QTextDocument testdoc;
    QTextCursor testcursor(&testdoc);
    QImage img(pixNotesPage.toImage());
    testcursor.insertImage(img);

    here pixNotesPage is a high resolution pixmap rendered from a scene..

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 2 Aug 2020, 09:20 last edited by
      #2

      Hi

      • inserting high resolution images results in only a small part of image getting displayed in the resulting word document.

      Well if image is wider than the page, you must scale it down so it fits.

      Is that what you are seeing ?

      • how to have multiple pages in the word doc with each page having its own size.
        As far as i know its not possible as each page shares its size with rest of the document.
        But you can use multiple documents to get same effect.
      1 Reply Last reply
      3
      • S Offline
        S Offline
        sachinrd
        wrote on 3 Aug 2020, 14:28 last edited by
        #3

        @mrjj thank you for the response.

        • I tried scaling down the image. I am losing the resolution of the image after scaling down. I want to add a high resolution image.(note:i did use smooth transformation mode)

        • is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).

        Thank you in advance..

        M 1 Reply Last reply 3 Aug 2020, 15:17
        0
        • S sachinrd
          3 Aug 2020, 14:28

          @mrjj thank you for the response.

          • I tried scaling down the image. I am losing the resolution of the image after scaling down. I want to add a high resolution image.(note:i did use smooth transformation mode)

          • is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).

          Thank you in advance..

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 3 Aug 2020, 15:17 last edited by
          #4

          @sachinrd

          • I tried scaling down the image. I am losing the resolution of the image after scaling down. I want to add a high resolution image.(note:i did use smooth transformation mode)

          But if image is bigger than page, there is no way around down sizing it.

          What about generating the image to be the right size from the beginning ?

          • is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).
            As far as i know, nope.
            But cant you use
            https://doc.qt.io/qt-5/qtextdocumentwriter.html#write
            and write multiple QTextDocument to same output ?
          S 1 Reply Last reply 3 Aug 2020, 19:04
          1
          • M mrjj
            3 Aug 2020, 15:17

            @sachinrd

            • I tried scaling down the image. I am losing the resolution of the image after scaling down. I want to add a high resolution image.(note:i did use smooth transformation mode)

            But if image is bigger than page, there is no way around down sizing it.

            What about generating the image to be the right size from the beginning ?

            • is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).
              As far as i know, nope.
              But cant you use
              https://doc.qt.io/qt-5/qtextdocumentwriter.html#write
              and write multiple QTextDocument to same output ?
            S Offline
            S Offline
            sachinrd
            wrote on 3 Aug 2020, 19:04 last edited by sachinrd 8 Mar 2020, 19:07
            #5

            @mrjj
            -is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).
            As far as i know, nope.
            But cant you use
            https://doc.qt.io/qt-5/qtextdocumentwriter.html#write
            and write multiple QTextDocument to same output ?

               * I tried this.Only the latest textdocument is being outputted to the word doc.
            
                QTextDocumentWriter writer("/Users/sachinr/Desktop/test.odt");
                writer.setFormat("odf"); // same as writer.setFormat("ODF");
                writer.write(&qtdoc);
                writer.write(&testdoc);
            
            M 1 Reply Last reply 3 Aug 2020, 19:18
            0
            • S sachinrd
              3 Aug 2020, 19:04

              @mrjj
              -is there a way to combine multiple textdocs into one.(i want a single textdoc to be generated i.e single word doc).
              As far as i know, nope.
              But cant you use
              https://doc.qt.io/qt-5/qtextdocumentwriter.html#write
              and write multiple QTextDocument to same output ?

                 * I tried this.Only the latest textdocument is being outputted to the word doc.
              
                  QTextDocumentWriter writer("/Users/sachinr/Desktop/test.odt");
                  writer.setFormat("odf"); // same as writer.setFormat("ODF");
                  writer.write(&qtdoc);
                  writer.write(&testdoc);
              
              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 3 Aug 2020, 19:18 last edited by
              #6

              Hi
              Thats odd as code goes

              bool QTextDocumentWriter::write(const QTextDocument *document)
              {
                  QByteArray suffix;
                  if (d->device && d->format.isEmpty()) {
                      // if there's no format, see if device is a file, and if so, find
                      // the file suffix
                      if (QFile *file = qobject_cast<QFile *>(d->device))
                          suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1();
                  }
                  QByteArray format = !d->format.isEmpty() ? d->format.toLower() : suffix;
              #ifndef QT_NO_TEXTODFWRITER
                  if (format == "odf" || format == "opendocumentformat" || format == "odt") {
                      QTextOdfWriter writer(*document, d->device);
              #if QT_CONFIG(textcodec)
                      writer.setCodec(d->codec);
              #endif
                      return writer.writeAll();
                  }
              #endif // QT_NO_TEXTODFWRITER
              

              and seems not to close d->device

              https://code.woboq.org/qt5/qtbase/src/gui/text/qtextodfwriter.cpp.html#_ZN14QTextOdfWriter8writeAllEv

              so not sure why only last is saved.

              S 1 Reply Last reply 4 Aug 2020, 05:25
              0
              • M mrjj
                3 Aug 2020, 19:18

                Hi
                Thats odd as code goes

                bool QTextDocumentWriter::write(const QTextDocument *document)
                {
                    QByteArray suffix;
                    if (d->device && d->format.isEmpty()) {
                        // if there's no format, see if device is a file, and if so, find
                        // the file suffix
                        if (QFile *file = qobject_cast<QFile *>(d->device))
                            suffix = QFileInfo(file->fileName()).suffix().toLower().toLatin1();
                    }
                    QByteArray format = !d->format.isEmpty() ? d->format.toLower() : suffix;
                #ifndef QT_NO_TEXTODFWRITER
                    if (format == "odf" || format == "opendocumentformat" || format == "odt") {
                        QTextOdfWriter writer(*document, d->device);
                #if QT_CONFIG(textcodec)
                        writer.setCodec(d->codec);
                #endif
                        return writer.writeAll();
                    }
                #endif // QT_NO_TEXTODFWRITER
                

                and seems not to close d->device

                https://code.woboq.org/qt5/qtbase/src/gui/text/qtextodfwriter.cpp.html#_ZN14QTextOdfWriter8writeAllEv

                so not sure why only last is saved.

                S Offline
                S Offline
                sachinrd
                wrote on 4 Aug 2020, 05:25 last edited by
                #7

                @mrjj
                Thanks for the response.
                So is there any way i could generate a word doc report with multiple pages of different sizes or i already have a pdf file generated. Can i convert the pdf file to doc format in qt ?(in that case i dont have to generate textdoc itself)..Is there any reliable 3rd party library as such?

                Thank you

                1 Reply Last reply
                0

                2/7

                2 Aug 2020, 09:20

                5 unread
                • Login

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