Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Make Table in Pdf
Forum Updated to NodeBB v4.3 + New Features

Make Table in Pdf

Scheduled Pinned Locked Moved Qt Creator and other tools
3 Posts 2 Posters 1.6k 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.
  • M Offline
    M Offline
    MrLibya
    wrote on last edited by
    #1

    Hello
    I was trying to make Pdf file with table , so with QPainter is kind of hard ! , so i chose to use it in HTML but didn't work

    QString html ="<html><head/><body>"
                "<h2 style=color: #2e6c80; text-align: center;>%1 - %2 - %3</h2>"
        "<p style=text-align: center;>&nbsp;</p>"
        "<p style=text-align: center;><strong>&nbsp;</strong></p>"
        "<table style=height: 212px; width=575>"
        "<tbody>"
        "<tr>"
        "<td>"
        "<h2>1-2</h2>"
        "</td>"
        "<td>"
        "<h2>12-1</h2>"
        "</td>"
        "<td>"
        "<h2>11-12</h2>"
        "</td>"
        "<td>"
        "<h2>10-11</h2>"
        "</td>"
        "<td>"
        "<h2>9-10</h2>"
        "</td>"
        "<td>"
        "<h2>8-9</h2>"
        "</td>"
        "<td>"
        "<h2>السنة</h2>"
        "</td>"
        "<td>"
        "<h2>ايام الأسبوع</h2>"
        "</td>"
        "</tr>"
        "<tr>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>"
        "<h3>السبت</h3>"
        "</td>"
        "</tr>"
        "<tr>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "<td>&nbsp;</td>"
        "</tbody>"
        "</table>"
        "</body></html>";
        QTextDocument document;
        document.setHtml(html.arg(ConfigDialog::_university,ConfigDialog::_college,ConfigDialog::_department));
        QPrinter printer;
        printer.setPageMargins(QMarginsF(15, 15, 15, 15));
        printer.setOutputFormat(QPrinter::PdfFormat);
        printer.setPageSize(QPrinter::A4);
        printer.printRange();
        printer.setOutputFileName("table.pdf");
        document.print(&printer);
    

    so what i should chose?

    jsulmJ 1 Reply Last reply
    0
    • M MrLibya

      Hello
      I was trying to make Pdf file with table , so with QPainter is kind of hard ! , so i chose to use it in HTML but didn't work

      QString html ="<html><head/><body>"
                  "<h2 style=color: #2e6c80; text-align: center;>%1 - %2 - %3</h2>"
          "<p style=text-align: center;>&nbsp;</p>"
          "<p style=text-align: center;><strong>&nbsp;</strong></p>"
          "<table style=height: 212px; width=575>"
          "<tbody>"
          "<tr>"
          "<td>"
          "<h2>1-2</h2>"
          "</td>"
          "<td>"
          "<h2>12-1</h2>"
          "</td>"
          "<td>"
          "<h2>11-12</h2>"
          "</td>"
          "<td>"
          "<h2>10-11</h2>"
          "</td>"
          "<td>"
          "<h2>9-10</h2>"
          "</td>"
          "<td>"
          "<h2>8-9</h2>"
          "</td>"
          "<td>"
          "<h2>السنة</h2>"
          "</td>"
          "<td>"
          "<h2>ايام الأسبوع</h2>"
          "</td>"
          "</tr>"
          "<tr>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>"
          "<h3>السبت</h3>"
          "</td>"
          "</tr>"
          "<tr>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "<td>&nbsp;</td>"
          "</tbody>"
          "</table>"
          "</body></html>";
          QTextDocument document;
          document.setHtml(html.arg(ConfigDialog::_university,ConfigDialog::_college,ConfigDialog::_department));
          QPrinter printer;
          printer.setPageMargins(QMarginsF(15, 15, 15, 15));
          printer.setOutputFormat(QPrinter::PdfFormat);
          printer.setPageSize(QPrinter::A4);
          printer.printRange();
          printer.setOutputFileName("table.pdf");
          document.print(&printer);
      

      so what i should chose?

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

      @MrLibya What exactly didn't work?
      Did you check that this HTML is interpreted correctly by QTextDocument (you can try to display it)?

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

      M 1 Reply Last reply
      0
      • jsulmJ jsulm

        @MrLibya What exactly didn't work?
        Did you check that this HTML is interpreted correctly by QTextDocument (you can try to display it)?

        M Offline
        M Offline
        MrLibya
        wrote on last edited by
        #3

        @jsulm no i didn't check , anyway I've used QTableWidget with span function and it dose what i want , and i will use render for the print on pdf file :)

        1 Reply Last reply
        0

        • Login

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