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. Create and write into a PDF File
Servers for Qt installer are currently down

Create and write into a PDF File

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 8 Posters 21.3k Views 4 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.
  • D Offline
    D Offline
    drich
    wrote on 12 Jul 2017, 11:54 last edited by
    #8

    Hi I want to create a program that will create a pdf file with a logo/image to it. using a QPrintPreviewDialog, QPixmap, QPrint, QDialog.

    M 1 Reply Last reply 12 Jul 2017, 12:00
    0
    • D drich
      12 Jul 2017, 11:54

      Hi I want to create a program that will create a pdf file with a logo/image to it. using a QPrintPreviewDialog, QPixmap, QPrint, QDialog.

      M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 12 Jul 2017, 12:00 last edited by
      #9

      @drich
      hi
      Its same concept.
      Just use
      painter2.drawPixmap instead of drawText

      D 1 Reply Last reply 12 Jul 2017, 12:02
      1
      • M mrjj
        12 Jul 2017, 12:00

        @drich
        hi
        Its same concept.
        Just use
        painter2.drawPixmap instead of drawText

        D Offline
        D Offline
        drich
        wrote on 12 Jul 2017, 12:02 last edited by
        #10

        @mrjj
        thanks
        I still having error.
        This is my code
        void MainWindow::on_pushButton_createpdf_clicked()
        {
        QPrintPreviewDialog dialog;
        QPainter painter(this);
        connect(&dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
        dialog.exec();
        painter.setPen(Qt::black);
        painter.setFont(QFont("Arial", 30));
        painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");
        painter.end();
        painter.drawPixmap (C:\User\Downloads\logo.png);
        }

        A J 2 Replies Last reply 12 Jul 2017, 12:09
        0
        • D drich
          12 Jul 2017, 12:02

          @mrjj
          thanks
          I still having error.
          This is my code
          void MainWindow::on_pushButton_createpdf_clicked()
          {
          QPrintPreviewDialog dialog;
          QPainter painter(this);
          connect(&dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
          dialog.exec();
          painter.setPen(Qt::black);
          painter.setFont(QFont("Arial", 30));
          painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");
          painter.end();
          painter.drawPixmap (C:\User\Downloads\logo.png);
          }

          A Offline
          A Offline
          artwaw
          wrote on 12 Jul 2017, 12:09 last edited by
          #11

          @drich Hi,
          what kind of an error?
          Have you read the QPainter documentation?

          For more information please re-read.

          Kind Regards,
          Artur

          D 1 Reply Last reply 12 Jul 2017, 12:19
          1
          • D drich
            12 Jul 2017, 12:02

            @mrjj
            thanks
            I still having error.
            This is my code
            void MainWindow::on_pushButton_createpdf_clicked()
            {
            QPrintPreviewDialog dialog;
            QPainter painter(this);
            connect(&dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
            dialog.exec();
            painter.setPen(Qt::black);
            painter.setFont(QFont("Arial", 30));
            painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");
            painter.end();
            painter.drawPixmap (C:\User\Downloads\logo.png);
            }

            J Online
            J Online
            jsulm
            Lifetime Qt Champion
            wrote on 12 Jul 2017, 12:13 last edited by
            #12

            @drich said in Create and write into a PDF File:

            painter.end();
            painter.drawPixmap (C:\User\Downloads\logo.png);

            I guess

            painter.end();
            

            should be last line and

            painter.drawPixmap (C:\User\Downloads\logo.png);
            

            is not valid C++. Should be:

            painter.drawPixmap ("C:/User/Downloads/logo.png");

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            D 1 Reply Last reply 12 Jul 2017, 12:14
            0
            • J jsulm
              12 Jul 2017, 12:13

              @drich said in Create and write into a PDF File:

              painter.end();
              painter.drawPixmap (C:\User\Downloads\logo.png);

              I guess

              painter.end();
              

              should be last line and

              painter.drawPixmap (C:\User\Downloads\logo.png);
              

              is not valid C++. Should be:

              painter.drawPixmap ("C:/User/Downloads/logo.png");
              D Offline
              D Offline
              drich
              wrote on 12 Jul 2017, 12:14 last edited by
              #13

              @jsulm ahh okie thanks. I try it.

              1 Reply Last reply
              0
              • A artwaw
                12 Jul 2017, 12:09

                @drich Hi,
                what kind of an error?
                Have you read the QPainter documentation?

                D Offline
                D Offline
                drich
                wrote on 12 Jul 2017, 12:19 last edited by
                #14

                @artwaw it says error: no matching function for call to 'QPainter::drawPixmap(const char [52])'

                A 1 Reply Last reply 12 Jul 2017, 12:20
                0
                • D drich
                  12 Jul 2017, 12:19

                  @artwaw it says error: no matching function for call to 'QPainter::drawPixmap(const char [52])'

                  A Offline
                  A Offline
                  artwaw
                  wrote on 12 Jul 2017, 12:20 last edited by
                  #15

                  @drich That's the problem @jsulm addressed in his reply.

                  For more information please re-read.

                  Kind Regards,
                  Artur

                  D 2 Replies Last reply 12 Jul 2017, 12:25
                  0
                  • A artwaw
                    12 Jul 2017, 12:20

                    @drich That's the problem @jsulm addressed in his reply.

                    D Offline
                    D Offline
                    drich
                    wrote on 12 Jul 2017, 12:25 last edited by
                    #16

                    @artwaw in the painter.drawPixmap

                    drawPixmap was underlined and it note "Too few arguments"

                    what does it means?

                    A 1 Reply Last reply 12 Jul 2017, 12:30
                    0
                    • A artwaw
                      12 Jul 2017, 12:20

                      @drich That's the problem @jsulm addressed in his reply.

                      D Offline
                      D Offline
                      drich
                      wrote on 12 Jul 2017, 12:30 last edited by
                      #17

                      @artwaw hi, I remove the painter.Pixmap and I run my program I clicked the createpdf button and it show a blank paper it didn't show this
                      painter.setPen(Qt::black);
                      painter.setFont(QFont("Arial", 30));
                      painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");

                      A 1 Reply Last reply 12 Jul 2017, 12:34
                      0
                      • D drich
                        12 Jul 2017, 12:25

                        @artwaw in the painter.drawPixmap

                        drawPixmap was underlined and it note "Too few arguments"

                        what does it means?

                        A Offline
                        A Offline
                        artwaw
                        wrote on 12 Jul 2017, 12:30 last edited by
                        #18

                        @drich That means that you passed too few arguments to the method. Please refer to the documentation I linked in one of my previous posts - in that webpage together with a quite detailed overview on how to use QPainter there is also a list of the methods provided. You will see that QPainter::drawPixmap comes in many variants with different arguments list so you can choose the one that best suits your needs.
                        It seems to me that taking a look at Paint System would also bring you some significant benefits in terms of overall understanding how to accomplish what you aim for.

                        For more information please re-read.

                        Kind Regards,
                        Artur

                        D 1 Reply Last reply 12 Jul 2017, 12:39
                        2
                        • D drich
                          12 Jul 2017, 12:30

                          @artwaw hi, I remove the painter.Pixmap and I run my program I clicked the createpdf button and it show a blank paper it didn't show this
                          painter.setPen(Qt::black);
                          painter.setFont(QFont("Arial", 30));
                          painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");

                          A Offline
                          A Offline
                          artwaw
                          wrote on 12 Jul 2017, 12:34 last edited by
                          #19

                          @drich I think that is because you have not had supplied a valid rectangle area which tells QPainter::drawText() where to draw. Please refer to the documentation I linked above to learn how to draw on widgets. It would be more helpful and consistent than explaining every detail in here.

                          For more information please re-read.

                          Kind Regards,
                          Artur

                          1 Reply Last reply
                          0
                          • A artwaw
                            12 Jul 2017, 12:30

                            @drich That means that you passed too few arguments to the method. Please refer to the documentation I linked in one of my previous posts - in that webpage together with a quite detailed overview on how to use QPainter there is also a list of the methods provided. You will see that QPainter::drawPixmap comes in many variants with different arguments list so you can choose the one that best suits your needs.
                            It seems to me that taking a look at Paint System would also bring you some significant benefits in terms of overall understanding how to accomplish what you aim for.

                            D Offline
                            D Offline
                            drich
                            wrote on 12 Jul 2017, 12:39 last edited by
                            #20

                            @artwaw Now I understand Thank you very much! :)

                            A 1 Reply Last reply 12 Jul 2017, 12:41
                            0
                            • D drich
                              12 Jul 2017, 12:39

                              @artwaw Now I understand Thank you very much! :)

                              A Offline
                              A Offline
                              artwaw
                              wrote on 12 Jul 2017, 12:41 last edited by
                              #21

                              @drich My pleasure.

                              For more information please re-read.

                              Kind Regards,
                              Artur

                              1 Reply Last reply
                              2

                              17/21

                              12 Jul 2017, 12:30

                              • Login

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