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

Create and write into a PDF File

Scheduled Pinned Locked Moved Solved General and Desktop
21 Posts 8 Posters 21.3k 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.
  • D Offline
    D Offline
    drich
    wrote on 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.

    mrjjM 1 Reply Last reply
    0
    • D drich

      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.

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

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

      D 1 Reply Last reply
      1
      • mrjjM mrjj

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

        D Offline
        D Offline
        drich
        wrote on 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);
        }

        artwawA jsulmJ 2 Replies Last reply
        0
        • D drich

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

          artwawA Offline
          artwawA Offline
          artwaw
          wrote on 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
          1
          • D drich

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

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on 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
            0
            • jsulmJ jsulm

              @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 last edited by
              #13

              @jsulm ahh okie thanks. I try it.

              1 Reply Last reply
              0
              • artwawA artwaw

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

                D Offline
                D Offline
                drich
                wrote on last edited by
                #14

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

                artwawA 1 Reply Last reply
                0
                • D drich

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

                  artwawA Offline
                  artwawA Offline
                  artwaw
                  wrote on 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
                  0
                  • artwawA artwaw

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

                    D Offline
                    D Offline
                    drich
                    wrote on last edited by
                    #16

                    @artwaw in the painter.drawPixmap

                    drawPixmap was underlined and it note "Too few arguments"

                    what does it means?

                    artwawA 1 Reply Last reply
                    0
                    • artwawA artwaw

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

                      D Offline
                      D Offline
                      drich
                      wrote on 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");

                      artwawA 1 Reply Last reply
                      0
                      • D drich

                        @artwaw in the painter.drawPixmap

                        drawPixmap was underlined and it note "Too few arguments"

                        what does it means?

                        artwawA Offline
                        artwawA Offline
                        artwaw
                        wrote on 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
                        2
                        • D drich

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

                          artwawA Offline
                          artwawA Offline
                          artwaw
                          wrote on 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
                          • artwawA artwaw

                            @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 last edited by
                            #20

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

                            artwawA 1 Reply Last reply
                            0
                            • D drich

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

                              artwawA Offline
                              artwawA Offline
                              artwaw
                              wrote on last edited by
                              #21

                              @drich My pleasure.

                              For more information please re-read.

                              Kind Regards,
                              Artur

                              1 Reply Last reply
                              2

                              • Login

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