Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Printing a simple pdf
Forum Updated to NodeBB v4.3 + New Features

Printing a simple pdf

Scheduled Pinned Locked Moved Unsolved Qt for Python
11 Posts 4 Posters 2.2k 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.
  • L LT-K101

    Hi,
    How can I print the text and image to a printer on a A4 paper or save to pdf from the image below in a form of report using a reporting tool like crystal report.

    Screenshot (88).png

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @LT-K101 Take a look at https://doc.qt.io/qt-5/qtprintsupport-index.html
    To write to PDF see: https://wiki.qt.io/Exporting_a_document_to_PDF

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

    L 1 Reply Last reply
    2
    • jsulmJ jsulm

      @LT-K101 Take a look at https://doc.qt.io/qt-5/qtprintsupport-index.html
      To write to PDF see: https://wiki.qt.io/Exporting_a_document_to_PDF

      L Offline
      L Offline
      LT-K101
      wrote on last edited by
      #3

      @jsulm The documentation is in C++ I tried over the weekend to understand but I'm finding difficult to do so because I don't know C++.

      jsulmJ 1 Reply Last reply
      0
      • L LT-K101

        @jsulm The documentation is in C++ I tried over the weekend to understand but I'm finding difficult to do so because I don't know C++.

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @LT-K101 Then you should tell what exactly is not clear.

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

        L 1 Reply Last reply
        0
        • jsulmJ jsulm

          @LT-K101 Then you should tell what exactly is not clear.

          L Offline
          L Offline
          LT-K101
          wrote on last edited by
          #5

          @jsulm Implementing it in python is my headache.

          JonBJ jsulmJ 2 Replies Last reply
          0
          • L LT-K101

            @jsulm Implementing it in python is my headache.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #6

            @LT-K101 said in Printing a simple pdf:

            @jsulm Implementing it in python is my headache.

            Many, many examples of Qt code are in C++, not Python. You are going to struggle if you are not prepared to look at C++ and translate for yourself into Python. It really is not too hard, most Qt calls are pretty similar, some common sense/guesswork should allow you to translate C++ to Python from simple example code without knowing all the ins & outs of C++.

            1 Reply Last reply
            0
            • L LT-K101

              @jsulm Implementing it in python is my headache.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @LT-K101 But you looked at C++ code and struggle to translate it to Python, right? So, what exactly is your current problem? What C++ code you can't translate to Python?

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

              L 1 Reply Last reply
              0
              • jsulmJ jsulm

                @LT-K101 But you looked at C++ code and struggle to translate it to Python, right? So, what exactly is your current problem? What C++ code you can't translate to Python?

                L Offline
                L Offline
                LT-K101
                wrote on last edited by
                #8

                @jsulm This is the C++ code

                QString fileName = QFileDialog::getSaveFileName((QWidget* )0, "Export PDF", QString(), "*.pdf");
                   if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); }
                
                   QPrinter printer(QPrinter::PrinterResolution);
                   printer.setOutputFormat(QPrinter::PdfFormat);
                   printer.setPaperSize(QPrinter::A4);
                   printer.setOutputFileName(fileName);
                
                
                jsulmJ CristianMaureiraC 2 Replies Last reply
                0
                • L LT-K101

                  @jsulm This is the C++ code

                  QString fileName = QFileDialog::getSaveFileName((QWidget* )0, "Export PDF", QString(), "*.pdf");
                     if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); }
                  
                     QPrinter printer(QPrinter::PrinterResolution);
                     printer.setOutputFormat(QPrinter::PdfFormat);
                     printer.setPaperSize(QPrinter::A4);
                     printer.setOutputFileName(fileName);
                  
                  
                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  @LT-K101 And the problem you have is what? This C++ code is easy to translate to Python.

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

                  1 Reply Last reply
                  1
                  • L LT-K101

                    @jsulm This is the C++ code

                    QString fileName = QFileDialog::getSaveFileName((QWidget* )0, "Export PDF", QString(), "*.pdf");
                       if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); }
                    
                       QPrinter printer(QPrinter::PrinterResolution);
                       printer.setOutputFormat(QPrinter::PdfFormat);
                       printer.setPaperSize(QPrinter::A4);
                       printer.setOutputFileName(fileName);
                    
                    
                    CristianMaureiraC Offline
                    CristianMaureiraC Offline
                    CristianMaureira
                    wrote on last edited by
                    #10

                    @LT-K101 said in Printing a simple pdf:

                    QString fileName = QFileDialog::getSaveFileName((QWidget* )0, "Export PDF", QString(), "*.pdf");
                    if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); }

                    QPrinter printer(QPrinter::PrinterResolution);
                    printer.setOutputFormat(QPrinter::PdfFormat);
                    printer.setPaperSize(QPrinter::A4);
                    printer.setOutputFileName(fileName);

                    without testing, it's not too different:

                    fileName = QFileDialog.getSaveFileName(0, "Export PDF", "", "*.pdf")
                    if (QFileInfo(fileName).suffix().isEmpty()):
                        fileName.append(".pdf")
                    
                    printer = QPrinter(QPrinter.PrinterResolution)
                    printer.setOutputFormat(QPrinter.PdfFormat)
                    printer.setPaperSize(QPrinter.A4)
                    printer.setOutputFileName(fileName)
                    

                    Better will be if you share your translation, or the part that doesn't work, otherwise we can just guess.

                    JonBJ 1 Reply Last reply
                    1
                    • CristianMaureiraC CristianMaureira

                      @LT-K101 said in Printing a simple pdf:

                      QString fileName = QFileDialog::getSaveFileName((QWidget* )0, "Export PDF", QString(), "*.pdf");
                      if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); }

                      QPrinter printer(QPrinter::PrinterResolution);
                      printer.setOutputFormat(QPrinter::PdfFormat);
                      printer.setPaperSize(QPrinter::A4);
                      printer.setOutputFileName(fileName);

                      without testing, it's not too different:

                      fileName = QFileDialog.getSaveFileName(0, "Export PDF", "", "*.pdf")
                      if (QFileInfo(fileName).suffix().isEmpty()):
                          fileName.append(".pdf")
                      
                      printer = QPrinter(QPrinter.PrinterResolution)
                      printer.setOutputFormat(QPrinter.PdfFormat)
                      printer.setPaperSize(QPrinter.A4)
                      printer.setOutputFileName(fileName)
                      

                      Better will be if you share your translation, or the part that doesn't work, otherwise we can just guess.

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by
                      #11

                      @CristianMaureira said in Printing a simple pdf:

                      fileName = QFileDialog.getSaveFileName(0, "Export PDF", "", "*.pdf")

                      The OP may need to use None in place of the 0 here.

                      1 Reply Last reply
                      0
                      • jsulmJ jsulm referenced this topic

                      • Login

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