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

Combine Multiple Images Into a Single PDF

Scheduled Pinned Locked Moved Unsolved General and Desktop
pdfsavewidget
38 Posts 7 Posters 34.7k 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.
  • ? A Former User
    30 Jun 2016, 18:29

    @geor :-)

    G Offline
    G Offline
    geor
    wrote on 20 Jul 2016, 19:53 last edited by
    #12

    @Wieland I keep getting qpainter::begin() reutnr false

    I am even using your exact code

            const QString fileName("C:/Qt");
    const QImage image("C:/Users/georg/Desktop/testPdf/Untitled.jpg");
    const QPoint imageCoordinates(0,0);
    
    QPdfWriter pdfWriter(fileName);
    pdfWriter.setPageSize(QPagedPaintDevice::A1);
    QPainter painter(&pdfWriter);
    
    for (int i=0; i<3; ++i)
    {
        painter.drawImage(imageCoordinates, image);
        pdfWriter.newPage();
        qDebug()<<2;
    }
    

    except for the page size becuase I am using qt 5.2.1

    do you have any idea why ebcuase I cannot figure it out the debug still runs i just get the eror and it does not save

    M 1 Reply Last reply 20 Jul 2016, 20:07
    1
    • G geor
      20 Jul 2016, 19:53

      @Wieland I keep getting qpainter::begin() reutnr false

      I am even using your exact code

              const QString fileName("C:/Qt");
      const QImage image("C:/Users/georg/Desktop/testPdf/Untitled.jpg");
      const QPoint imageCoordinates(0,0);
      
      QPdfWriter pdfWriter(fileName);
      pdfWriter.setPageSize(QPagedPaintDevice::A1);
      QPainter painter(&pdfWriter);
      
      for (int i=0; i<3; ++i)
      {
          painter.drawImage(imageCoordinates, image);
          pdfWriter.newPage();
          qDebug()<<2;
      }
      

      except for the page size becuase I am using qt 5.2.1

      do you have any idea why ebcuase I cannot figure it out the debug still runs i just get the eror and it does not save

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 20 Jul 2016, 20:07 last edited by
      #13

      @geor said:

      const QString fileName("C:/Qt");

      that is the actual filename ?

      I would expect something like
      const QString fileName("c:/mydoc.pdf");

      G 1 Reply Last reply 20 Jul 2016, 20:51
      2
      • ? Offline
        ? Offline
        A Former User
        wrote on 20 Jul 2016, 20:08 last edited by
        #14

        To add to what @mrjj said, do you have write access to C:/?

        G 2 Replies Last reply 20 Jul 2016, 20:57
        3
        • M mrjj
          20 Jul 2016, 20:07

          @geor said:

          const QString fileName("C:/Qt");

          that is the actual filename ?

          I would expect something like
          const QString fileName("c:/mydoc.pdf");

          G Offline
          G Offline
          geor
          wrote on 20 Jul 2016, 20:51 last edited by
          #15

          @mrjj said:

          @
          I still get the same error

          M 1 Reply Last reply 20 Jul 2016, 21:04
          0
          • ? A Former User
            20 Jul 2016, 20:08

            To add to what @mrjj said, do you have write access to C:/?

            G Offline
            G Offline
            geor
            wrote on 20 Jul 2016, 20:57 last edited by
            #16
            This post is deleted!
            1 Reply Last reply
            0
            • ? A Former User
              20 Jul 2016, 20:08

              To add to what @mrjj said, do you have write access to C:/?

              G Offline
              G Offline
              geor
              wrote on 20 Jul 2016, 21:03 last edited by
              #17

              @Wieland

              once again thank you for your help it worked when I switch to the drive where the build is saved .However for some reason it is 4 empty pages maybe it's becuase of the size or something I'll try another image and see but again thank you

              M 1 Reply Last reply 20 Jul 2016, 21:04
              0
              • G geor
                20 Jul 2016, 20:51

                @mrjj said:

                @
                I still get the same error

                M Offline
                M Offline
                mrjj
                Lifetime Qt Champion
                wrote on 20 Jul 2016, 21:04 last edited by
                #18

                @geor
                I think its just a path thing

                void writePdf()
                {
                    const QString fileName("e:/mydoc.pdf");
                       QPdfWriter pdfWriter(fileName);
                    pdfWriter.setPageSize(QPageSize(QPageSize::A4));
                    QPainter painter(&pdfWriter);
                
                    for (int i=0; i<3; ++i) {
                        painter.drawPixmap(QRect(0,0,pdfWriter.logicalDpiX()*8.3,pdfWriter.logicalDpiY()*11.7), QPixmap("e:/truck.png"));
                        pdfWriter.newPage();
                    }
                }
                
                works here. makes PDF on e:
                
                1 Reply Last reply
                2
                • G geor
                  20 Jul 2016, 21:03

                  @Wieland

                  once again thank you for your help it worked when I switch to the drive where the build is saved .However for some reason it is 4 empty pages maybe it's becuase of the size or something I'll try another image and see but again thank you

                  M Offline
                  M Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on 20 Jul 2016, 21:04 last edited by
                  #19

                  @geor
                  hi
                  You will / might need to scale the picture or its really small.

                  G 2 Replies Last reply 21 Jul 2016, 18:05
                  1
                  • M mrjj
                    20 Jul 2016, 21:04

                    @geor
                    hi
                    You will / might need to scale the picture or its really small.

                    G Offline
                    G Offline
                    geor
                    wrote on 21 Jul 2016, 18:05 last edited by
                    #20

                    @mrjj

                    yeh it worked after scaling thank you.

                    1 Reply Last reply
                    1
                    • M mrjj
                      20 Jul 2016, 21:04

                      @geor
                      hi
                      You will / might need to scale the picture or its really small.

                      G Offline
                      G Offline
                      geor
                      wrote on 21 Jul 2016, 21:10 last edited by
                      #21

                      @mrjj one more question lol

                      the size of my widget is too big to fit well on a A4 paper without looking deformed. So I want to break the layout of it's parent, resize my widget it and then take it's pixmap to put it in an A4 so it is not deformed (with the grab function) but the problem is I can't break the layout of the parent i can only delete (in code) and when I delete it it deletes everything in it any tips?

                      M 1 Reply Last reply 21 Jul 2016, 21:13
                      0
                      • G geor
                        21 Jul 2016, 21:10

                        @mrjj one more question lol

                        the size of my widget is too big to fit well on a A4 paper without looking deformed. So I want to break the layout of it's parent, resize my widget it and then take it's pixmap to put it in an A4 so it is not deformed (with the grab function) but the problem is I can't break the layout of the parent i can only delete (in code) and when I delete it it deletes everything in it any tips?

                        M Offline
                        M Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on 21 Jul 2016, 21:13 last edited by mrjj
                        #22

                        @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

                        G 1 Reply Last reply 22 Jul 2016, 14:44
                        3
                        • M mrjj
                          21 Jul 2016, 21:13

                          @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

                          G Offline
                          G Offline
                          geor
                          wrote on 22 Jul 2016, 14:44 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();
                          
                          M 1 Reply Last reply 22 Jul 2016, 17:53
                          1
                          • G geor
                            22 Jul 2016, 14:44

                            @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();
                            
                            M Offline
                            M Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on 22 Jul 2016, 17:53 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.

                            G 1 Reply Last reply 25 Jul 2016, 15:38
                            1
                            • M mrjj
                              22 Jul 2016, 17:53

                              @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.

                              G Offline
                              G Offline
                              geor
                              wrote on 25 Jul 2016, 15:38 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?

                              M 1 Reply Last reply 25 Jul 2016, 16:55
                              0
                              • G geor
                                25 Jul 2016, 15:38

                                @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?

                                M Offline
                                M Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on 25 Jul 2016, 16:55 last edited by
                                #26

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

                                G 1 Reply Last reply 25 Jul 2016, 17:45
                                0
                                • M mrjj
                                  25 Jul 2016, 16:55

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

                                  G Offline
                                  G Offline
                                  geor
                                  wrote on 25 Jul 2016, 17:45 last edited by
                                  #27

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

                                  M 1 Reply Last reply 25 Jul 2016, 17:48
                                  0
                                  • G geor
                                    25 Jul 2016, 17:45

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

                                    M Offline
                                    M Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on 25 Jul 2016, 17:48 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.

                                    G 1 Reply Last reply 25 Jul 2016, 18:28
                                    2
                                    • M mrjj
                                      25 Jul 2016, 17:48

                                      @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.

                                      G Offline
                                      G Offline
                                      geor
                                      wrote on 25 Jul 2016, 18:28 last edited by
                                      #29

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

                                      M 1 Reply Last reply 25 Jul 2016, 18:34
                                      0
                                      • G geor
                                        25 Jul 2016, 18:28

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

                                        M Offline
                                        M Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on 25 Jul 2016, 18:34 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)

                                        G 1 Reply Last reply 25 Jul 2016, 18:51
                                        1
                                        • M mrjj
                                          25 Jul 2016, 18:34

                                          @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)

                                          G Offline
                                          G Offline
                                          geor
                                          wrote on 25 Jul 2016, 18:51 last edited by
                                          #31

                                          @mrjj It is abit better but still low quality

                                          M 1 Reply Last reply 25 Jul 2016, 18:58
                                          0

                                          21/38

                                          21 Jul 2016, 21:10

                                          • Login

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