QWebView not respecting html <thead>



  • QWebView does not seem to respect <thead> code for tables. Other attributes including CSS that I have tried seem to be working fine.

    Here's what I'm doing:

    Create simple html code for a long table. Html code for table headers are enclosed in <thead></thead> so that they would be repeated when table spans more than one page.

    Assign the html code to a QWebView

    Print the QWebView to pdf using QPrinter

    What I expect is for the headers to be repeated when the table spans more than 1 page. But that's not the case. If I assign the same code to a QTextBrowser, it works fine: the headers are repeated in new pages. But I'd like to use a QWebView since it supports CSS better.

    Only other post related to this I found was "this":http://qtforum.de/forum/viewtopic.php?t=7855 dating back to 2008 (no responses) as well as this "bug":https://bugreports.qt.io/browse/QTBUG-31601 that appears to affect version 5. Any suggestions/guidance/comments would be greatly appreciated. Thanks.

    Some additional info:

    • Using Qt 4.8.2
    • Tried on Linux (Fedora) and Windows 7 (compiled with VS2010)
    • Removed full code below to bypass the "spam" detection

    Edit: I'm including the full code and the images of the resulting pdfs posted in comments for future refereces:

    @
    // --------------------------------------------------
    // QWebView approach:
    QWebView webView;
    webView.setHtml( generateHtmlTable(100) );

    printer.setOutputFileName("webViewOutput.pdf");
    webView.print(&printer);
    // --------------------------------------------------

    // --------------------------------------------------
    // QTextBrowser approach:
    QTextBrowser textBrowser;
    textBrowser.setHtml( generateHtmlTable(100) );

    printer.setOutputFileName("textBrowserOutput.pdf");
    textBrowser.print(&printer);
    // --------------------------------------------------
    @



  • Hi!

    can you publish all code of the html page?



  • I had it posted, but the page would forum would flag it as spam. So this time I'm putting them else where.

    Here is the full c++ code including the html part: http://pastebin.com/e4bmEyV7

    and here is only the html part: http://pastebin.com/k7BBERHf (there is an extra ``\n'' in one that should be removed)

    Thanks



  • the html code seems fine and webkit understand it

    http://disk.tom.ru/wuv1df7

    but in your project it don't work? isn't it?
    I think the problem in the generateHtmlTable function.

    well. will be looking for solve



  • It's funny but your code works fine :o\

    http://disk.tom.ru/nhpmrl1

    @QString htmlCode;

    int numLines=3;
    // Open html tags

    htmlCode =
    "<html>\n"
    " <body>\n"
    ""
    " <table>\n"
    " <thead>\n"
    " <tr>\n"
    " <th> Header 1 </th>\n"
    " <th> Header 2 </th>\n"
    " <th> Header 3 </th>\n"
    " </tr>\n"
    " </thead>\n";

    // Fill rows

    for (int i=0; i<numLines; ++i){
    htmlCode +=
    "<tr>\n";
    htmlCode += QString("<td> %0 </td>\n").arg(i);
    htmlCode += QString("<td> %0 </td>\n").arg(i+1);
    htmlCode += QString("<td> %0 </td>\n").arg(i+2);
    htmlCode +=
    "</tr>\n";
    }

    // Close tags

    htmlCode +=
    "</table>\n"
    "</body>\n"
    "</html>\n"
    ;
    qDebug()<<htmlCode;
    textBrowser->setHtml(htmlCode);
    webView->setHtml(htmlCode);

    QPrinter printer;
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName("d:/2.pdf");
    webView->print(&printer);@



  • I don't see a proper TBODY tag...

    "According to this description":https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody TBODY tag is responsible for printing THEAD and TFOOT on every page
    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/tbody

    (<tbody>) provides additional semantic information for devices such as printers and displays. Of the parent table's child elements, (<tbody>) will represent the content, if longer than a page, that will most likely differ for each page printed. The <tfoot> and <thead> elements' content will be consistent for each page printed.



  • The code compiles and runs fine. The problem is with the <thead> tag not beign respected when the table spans more than 2 pages and printed to pdf. See below for comparison between resulting PDFs generated from the code I posted:

    This is the result from QWebView (webViewOutput.pdf): http://i.imgur.com/i47qrdo.png
    Note the missing headers on second page

    This is the result from QTextBrowser (textBrowserOutput.pdf) which actually respects the <thead> tag:
    http://i.imgur.com/XxoC61b.png
    Note that the headers are automatically repeated on second page.



  • [quote author="ThatDude" date="1421162273"]I don't see a proper TBODY tag...

    [/quote]

    Thanks for your reply. I tried that, but the result is the same as before.



  • oh, sorry.
    I think webkit can't recognize the begin and end of page. And TBODY tag (as wrote ThatDude can't help in this case, it's usefull for block formatting)


Log in to reply
 

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