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. Combine Multiple Images Into a Single PDF
Servers for Qt installer are currently down

Combine Multiple Images Into a Single PDF

Scheduled Pinned Locked Moved Unsolved General and Desktop
pdfsavewidget
38 Posts 7 Posters 35.4k Views 2 Watching
  • 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.
  • mrjjM mrjj

    @geor
    Hi you can use the takeAt method to get your widget back from a layout.
    But maybe you can just ask the widget to render directly?
    it has a render function that can draw itself to anything you like.
    http://doc.qt.io/qt-5/qwidget.html#render

    georG Offline
    georG Offline
    geor
    wrote on last edited by
    #23

    @mrjj

    it doesn't seem to chnage much unless I am using it wrong? here is my code 1870 and 994 is the size of my widget.making the pixmap the same as the size of my widget gives me excatly the same ouput as before so i made it smaller it's better but cuts most of the widget out

                       ui->page1->setBackgroundRole(QPalette::BrightText);
    
                 QPixmap pixMap1(600,900);
               ui->page1->render(&pixMap1,QPoint(),QRegion(0,0,1870,994));
    
    
    
    
        const QString fileName("D:/mydoc2.pdf");
           QPdfWriter pdfWriter(fileName);
        pdfWriter.setPageSize(QPagedPaintDevice::A4);
        QPainter painter(&pdfWriter);
    
       
            painter.drawPixmap(QRect(0,0,pdfWriter.logicalDpiX()*8.3,pdfWriter.logicalDpiY()*11.7), pixMap1);
            pdfWriter.newPage();
    
    mrjjM 1 Reply Last reply
    1
    • georG geor

      @mrjj

      it doesn't seem to chnage much unless I am using it wrong? here is my code 1870 and 994 is the size of my widget.making the pixmap the same as the size of my widget gives me excatly the same ouput as before so i made it smaller it's better but cuts most of the widget out

                         ui->page1->setBackgroundRole(QPalette::BrightText);
      
                   QPixmap pixMap1(600,900);
                 ui->page1->render(&pixMap1,QPoint(),QRegion(0,0,1870,994));
      
      
      
      
          const QString fileName("D:/mydoc2.pdf");
             QPdfWriter pdfWriter(fileName);
          pdfWriter.setPageSize(QPagedPaintDevice::A4);
          QPainter painter(&pdfWriter);
      
         
              painter.drawPixmap(QRect(0,0,pdfWriter.logicalDpiX()*8.3,pdfWriter.logicalDpiY()*11.7), pixMap1);
              pdfWriter.newPage();
      
      mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #24

      @geor
      hi
      Sorry, didn't read the right docs.
      The rect is for clipping not resize the widget.
      So render will not help you to render it smaller.

      so yes, i guess to render it in different size, you must take widget out , call resize +render and put it back it.
      Not sure how well it will work if there is other stuff in the layout.
      If sole widget, it should work ok.

      georG 1 Reply Last reply
      1
      • mrjjM mrjj

        @geor
        hi
        Sorry, didn't read the right docs.
        The rect is for clipping not resize the widget.
        So render will not help you to render it smaller.

        so yes, i guess to render it in different size, you must take widget out , call resize +render and put it back it.
        Not sure how well it will work if there is other stuff in the layout.
        If sole widget, it should work ok.

        georG Offline
        georG Offline
        geor
        wrote on last edited by
        #25

        @mrjj Yeah I tried this method and It works but it's not perfect even if I resize the widget to the size of an A4 and then take it's pixmap fore some reason in the pdf it loses some quality (it looks a lot better in the user interface then in the pdf )even tho they are both the same size.I tried different functions from the painter class to draw the pixamp but the all seam the same not so good .If I draw the pixmap withouth any scaling it is very small in the pdf .. any ideas?

        mrjjM 1 Reply Last reply
        0
        • georG geor

          @mrjj Yeah I tried this method and It works but it's not perfect even if I resize the widget to the size of an A4 and then take it's pixmap fore some reason in the pdf it loses some quality (it looks a lot better in the user interface then in the pdf )even tho they are both the same size.I tried different functions from the painter class to draw the pixamp but the all seam the same not so good .If I draw the pixmap withouth any scaling it is very small in the pdf .. any ideas?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #26

          @geor
          hi , have you tried to render it really large and then
          scale down to fit A4?

          georG 1 Reply Last reply
          0
          • mrjjM mrjj

            @geor
            hi , have you tried to render it really large and then
            scale down to fit A4?

            georG Offline
            georG Offline
            geor
            wrote on last edited by
            #27

            @mrjj yep no matter how large the pixmap awlays appears very small on the pdf

            mrjjM 1 Reply Last reply
            0
            • georG geor

              @mrjj yep no matter how large the pixmap awlays appears very small on the pdf

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #28

              @geor
              well a screen is 72/96 DPI
              and a printer is 600/1200/2400 DPI
              so images do get really small.

              As far as I remember, QPdfWriter have some setting for pdf resolution.
              maybe it can produce better output.

              georG 1 Reply Last reply
              2
              • mrjjM mrjj

                @geor
                well a screen is 72/96 DPI
                and a printer is 600/1200/2400 DPI
                so images do get really small.

                As far as I remember, QPdfWriter have some setting for pdf resolution.
                maybe it can produce better output.

                georG Offline
                georG Offline
                geor
                wrote on last edited by
                #29

                @mrjj yeah I saw that but unfortunately I am using qt 5.2.1

                mrjjM 1 Reply Last reply
                0
                • georG geor

                  @mrjj yeah I saw that but unfortunately I am using qt 5.2.1

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by
                  #30

                  @geor
                  maybe you could try to scale it before
                  drawing it to pdf.
                  the scale function can be adjusted to aim for quality
                  http://doc.qt.io/qt-5/qpixmap.html#scaled
                  with Qt::SmoothTransformation

                  note. it returns the scaled pixmap not modify the original.
                  so something like
                  mypixmap = mypixmap.scaled(xx)

                  georG 1 Reply Last reply
                  1
                  • mrjjM mrjj

                    @geor
                    maybe you could try to scale it before
                    drawing it to pdf.
                    the scale function can be adjusted to aim for quality
                    http://doc.qt.io/qt-5/qpixmap.html#scaled
                    with Qt::SmoothTransformation

                    note. it returns the scaled pixmap not modify the original.
                    so something like
                    mypixmap = mypixmap.scaled(xx)

                    georG Offline
                    georG Offline
                    geor
                    wrote on last edited by
                    #31

                    @mrjj It is abit better but still low quality

                    mrjjM 1 Reply Last reply
                    0
                    • georG geor

                      @mrjj It is abit better but still low quality

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #32

                      @geor
                      well it was worth a shot.
                      I assume you play around with different scales?
                      Have you tried huge image like 1920x1080 and scale it down?
                      You are using http://doc.qt.io/qt-5/qpaintdevice.html#logicalDpiX
                      to calc how much to scale it?

                      I dont remember quality being so bad but i was using a fairly
                      large resolution so the widget was not that small.

                      georG 1 Reply Last reply
                      0
                      • mrjjM mrjj

                        @geor
                        well it was worth a shot.
                        I assume you play around with different scales?
                        Have you tried huge image like 1920x1080 and scale it down?
                        You are using http://doc.qt.io/qt-5/qpaintdevice.html#logicalDpiX
                        to calc how much to scale it?

                        I dont remember quality being so bad but i was using a fairly
                        large resolution so the widget was not that small.

                        georG Offline
                        georG Offline
                        geor
                        wrote on last edited by
                        #33

                        @mrjj yes I am using it the quality is not so good however if I save it into an image its gives me a good quality so it seems taking an image instead of a pixmap a lot better.
                        just like this
                        ui->myWidget->grab().save("image.png");
                        but this make me save 5 usless Images and I could not find a way to just use it temporarly..

                        mrjjM 1 Reply Last reply
                        0
                        • georG geor

                          @mrjj yes I am using it the quality is not so good however if I save it into an image its gives me a good quality so it seems taking an image instead of a pixmap a lot better.
                          just like this
                          ui->myWidget->grab().save("image.png");
                          but this make me save 5 usless Images and I could not find a way to just use it temporarly..

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by mrjj
                          #34

                          @geor
                          Im not sure what grab() is.
                          Does it return QImage?
                          Im wondering if u could just draw this directly?
                          No reason to save first.

                          georG 1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @geor
                            Im not sure what grab() is.
                            Does it return QImage?
                            Im wondering if u could just draw this directly?
                            No reason to save first.

                            georG Offline
                            georG Offline
                            geor
                            wrote on last edited by
                            #35

                            @mrjj it returns a pixmap

                            mrjjM 1 Reply Last reply
                            0
                            • georG geor

                              @mrjj it returns a pixmap

                              mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by mrjj
                              #36

                              @geor
                              have you tried to convert to qimage and draw it?
                              http://doc.qt.io/qt-4.8/qpixmap.html#toImage
                              Not sure why saving as png makes any difference.

                              1 Reply Last reply
                              1
                              • D Offline
                                D Offline
                                drich
                                wrote on last edited by
                                #37
                                This post is deleted!
                                1 Reply Last reply
                                0
                                • JonBJ Offline
                                  JonBJ Offline
                                  JonB
                                  wrote on last edited by JonB
                                  #38

                                  @MarieBurgan
                                  Thanks for the plug. I'm sure @geor will thank you for this tip, if he visits here now two years after he last posted... ;-)

                                  1 Reply Last reply
                                  1
                                  • Pl45m4P Pl45m4 referenced this topic on

                                  • Login

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