Make Table in Pdf



  • 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?


  • Moderators

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



  • @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 :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.