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
Forum Update on Monday, May 27th 2025

Combine Multiple Images Into a Single PDF

Scheduled Pinned Locked Moved Unsolved General and Desktop
pdfsavewidget
38 Posts 7 Posters 34.8k 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.
  • K Offline
    K Offline
    koronabora
    wrote on 29 Jun 2016, 15:22 last edited by koronabora
    #2

    Use one of them:

    1. http://podofo.sourceforge.net
    2. https://github.com/pocoproject/poco/tree/master/PDF
    G 1 Reply Last reply 29 Jun 2016, 18:08
    1
    • ? Offline
      ? Offline
      A Former User
      wrote on 29 Jun 2016, 15:27 last edited by
      #3

      Hi! No need for external libraries. QPdfWriter can create documents with multiple pages.

      G 1 Reply Last reply 29 Jun 2016, 18:02
      4
      • K Offline
        K Offline
        koronabora
        wrote on 29 Jun 2016, 15:34 last edited by
        #4

        I thought that if somebody asks this question, the answer from the documentation it is not suitable for him. I made a mistake.

        1 Reply Last reply
        2
        • ? A Former User
          29 Jun 2016, 15:27

          Hi! No need for external libraries. QPdfWriter can create documents with multiple pages.

          G Offline
          G Offline
          geor
          wrote on 29 Jun 2016, 18:02 last edited by
          #5

          @Wieland I took a look at the functions for that class and all I see is way to edit the pages but how do you add the images?

          thank you

          M ? 2 Replies Last reply 29 Jun 2016, 18:09
          0
          • K koronabora
            29 Jun 2016, 15:22

            Use one of them:

            1. http://podofo.sourceforge.net
            2. https://github.com/pocoproject/poco/tree/master/PDF
            G Offline
            G Offline
            geor
            wrote on 29 Jun 2016, 18:08 last edited by
            #6

            @koronabora thank you but I prefer not to use 3rd party lib

            1 Reply Last reply
            0
            • G geor
              29 Jun 2016, 18:02

              @Wieland I took a look at the functions for that class and all I see is way to edit the pages but how do you add the images?

              thank you

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 29 Jun 2016, 18:09 last edited by
              #7

              @geor
              Hi
              You draw the images to it.
              http://www.codeprogress.com/cpp/libraries/qt/showQtExample.php?index=570&key=QPdfWriterWriteImage

              Keep in mind about DPI.

              G 1 Reply Last reply 30 Jun 2016, 18:23
              4
              • G geor
                29 Jun 2016, 18:02

                @Wieland I took a look at the functions for that class and all I see is way to edit the pages but how do you add the images?

                thank you

                ? Offline
                ? Offline
                A Former User
                wrote on 29 Jun 2016, 18:26 last edited by
                #8

                @geor Like this:

                void writePdf()
                {
                    const QString fileName("/home/patrick/mydoc.pdf");
                    const QImage image("/home/patrick/truck.jpg");
                    const QPoint imageCoordinates(0,0);
                
                    QPdfWriter pdfWriter(fileName);
                    pdfWriter.setPageSize(QPageSize(QPageSize::A4));
                    QPainter painter(&pdfWriter);
                
                    for (int i=0; i<3; ++i) {
                        painter.drawImage(imageCoordinates, image);
                        pdfWriter.newPage();
                    }
                }
                
                G 1 Reply Last reply 30 Jun 2016, 18:28
                6
                • M mrjj
                  29 Jun 2016, 18:09

                  @geor
                  Hi
                  You draw the images to it.
                  http://www.codeprogress.com/cpp/libraries/qt/showQtExample.php?index=570&key=QPdfWriterWriteImage

                  Keep in mind about DPI.

                  G Offline
                  G Offline
                  geor
                  wrote on 30 Jun 2016, 18:23 last edited by
                  #9

                  @mrjj thank you

                  1 Reply Last reply
                  0
                  • ? A Former User
                    29 Jun 2016, 18:26

                    @geor Like this:

                    void writePdf()
                    {
                        const QString fileName("/home/patrick/mydoc.pdf");
                        const QImage image("/home/patrick/truck.jpg");
                        const QPoint imageCoordinates(0,0);
                    
                        QPdfWriter pdfWriter(fileName);
                        pdfWriter.setPageSize(QPageSize(QPageSize::A4));
                        QPainter painter(&pdfWriter);
                    
                        for (int i=0; i<3; ++i) {
                            painter.drawImage(imageCoordinates, image);
                            pdfWriter.newPage();
                        }
                    }
                    
                    G Offline
                    G Offline
                    geor
                    wrote on 30 Jun 2016, 18:28 last edited by
                    #10

                    @Wieland thank you

                    ? 1 Reply Last reply 30 Jun 2016, 18:29
                    0
                    • G geor
                      30 Jun 2016, 18:28

                      @Wieland thank you

                      ? Offline
                      ? Offline
                      A Former User
                      wrote on 30 Jun 2016, 18:29 last edited by
                      #11

                      @geor :-)

                      G 1 Reply Last reply 20 Jul 2016, 19:53
                      1
                      • ? 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

                                          • Login

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