B
B
BriGaDir_892015-07-02 09:15:38
JavaScript
BriGaDir_89, 2015-07-02 09:15:38

Html to pdf + QWebView + how to repeat table header on next page?

<table border="1">
   <thead>
    <tr>
      <td>COL 1</td><td>COL 2</td><td>COL 3</td>
    <tr>
   </thead>
   <tbody>
    <script language="JavaScript" type="text/javascript">
      for( var i = 0; i < 3; i ++ )
      {
        document.write( "<tr>" );
        for( var j = 0; j < 3; j ++ )
        {
          document.write("<td>");
          for( var k = 0; k < 20; k ++ )
            document.write( k + "<br>");
          document.write("</td>");
        }
        document.write( "</tr>" );
      }
    </script>
   </tbody>
  </table>

QString ResHTML = "здесь приведенный выше html.";
QWebView* printHtmlView = new QWebView();
printHtmlView->setHtml(ResHTML); // загружаем ваш html.    

QPrinter printer;
printer.setOutputFormat( QPrinter::PdfFormat);
printer.setOutputFileName( "файл.pdf" );

printHtmlView->print(&printer);

If you save this table in *.pdf, then the table will be simply cut at the page break.
And I would like to repeat the title on the next page.
784f2f43002344d582c3210a277a4bef.JPG

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-07-02
@BriGaDir_89

I had a similar problem with wkhtmltopdf (which internally uses Qt Webkit)
Solved by similar hacks
https://github.com/AAverin/JSUtils/tree/master/wkh...
https://gist.github.com/zenden2k/dc706de2f638ea9bac5f
maybe this will help you somehow

B
BriGaDir_89, 2015-07-02
@BriGaDir_89

If you even know any crutch method, share it too ...
If you use the QTextDocument object, then everything works as it should, but due to the flawed support of HTML and CSS tags by this object, this solution is not suitable for my task.

QTextDocument *document = new QTextDocument();
    document->setHtml(htmlContent);

    QPrinter printer(QPrinter::HighResolution);
    printer.setPageSize(QPrinter::A4);
    printer.setOutputFormat(QPrinter::PdfFormat);

    printer.setOutputFileName("output.pdf");

    document->print(&printer);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question