c++ - CHtmlEditCtrl::PrintDocument() - 靠近页面底部的行间距错误?

标签 c++ visual-c++ mfc

我正在尝试使用 CHtmlEditCtrl::PrintDocument() 的方法打印文档如此处所述(Printing In MFC Application)。下面是我的测试代码,我打算在其中打印一个非常大的表格。

void CMyView::OnFilePrint()
{
    CHtmlEditCtrl PrintCtrl;
    if (!PrintCtrl.Create(NULL, WS_CHILD, CRect(0, 0, 0, 0), this, 1))
    {
        ASSERT(FALSE);
        return;
    }

    CComPtr<IHTMLDocument2> document;
    PrintCtrl.GetDocument(&document);
    WaitForComplete(document);
    CString html = 
        _T("<!doctype html>")
        _T("<html lang=\"en\">")
        _T("  <head>")
        _T("    <meta charset=\"utf-8\">")
        _T("    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">")
        _T("    <title>HTML5 Test Page</title>")
        _T("    <style>")
        _T("      @media print")
        _T("      {")
        _T("        td { overflow-x:auto }")
        _T("      }")
        _T("    </style>")
        _T("    <style type=\"text/css\">")
        _T("      thead { display:table-header-group }")
        _T("      tfoot { display:table-footer-group; page-break-inside:avoid }")
        _T("      tbody { display:table-row-group }")
        _T("      td > div { display:block; page-break-inside:avoid }")
        _T("    </style>")
        _T("  </head>")
        _T("  <body>")
        _T("    <div id=\"top\" class=\"page\" role=\"document\">")
        _T("      <header role=\"banner\">")
        _T("        <p>This is header.</p>")
        _T("      </header>")
        _T("      <main role=\"main\">")
        _T("        <section id=\"text\">")
        _T("          <article id=\"text_tables\">")
        _T("            <table>")
        _T("            <thead>")
        _T("                <tr>")
        _T("                    <th>")
        _T("                        header comes here for each page")
        _T("                    </th>")
        _T("                </tr>")
        _T("            </thead>")
        _T("            <tfoot>")
        _T("                <tr>")
        _T("                    <td>")
        _T("                        footer comes here for each page")
        _T("                    </td>")
        _T("                </tr>")
        _T("            </tfoot>");
        _T("            <tbody>");
    for (int i = 0; i < 200; ++i)
    {
        CString str;
        str.Format(_T("%d"), i);
        html = html + "<tr><td><div>" + str + "</div></td></tr>";
    }
    html = html + "</tbody></table></article></section></main>";
    html = html + "<footer role=\"contentinfo\"><p>This is footer</p></footer></div></body></html>";
    PrintCtrl.SetDocumentHTML(html);
    WaitForComplete(document);
    //PrintCtrl.PrintPreview();
    PrintCtrl.PrintDocument();
}

问题在于页面底部附近的每一行,间距似乎很乱。请参见下面的附图,注意 41 与 40 之间的间距更大,并且被部分切断。它是如何发生的以及如何解决它?

enter image description here

我尝试添加重复的页眉和页脚,下面是显示错误的结果的一部分。

enter image description here

我尝试使用“td {overflow-x:auto;}”。第一页的表尾显示不正确。

enter image description here

最佳答案

这似乎是 IWebBrowser2 的错误。界面。可以用 td{overflow-x: auto;} 修复

<style>
@media print
{ 
    td{overflow-x: auto;} 
}
</style> 

关于c++ - CHtmlEditCtrl::PrintDocument() - 靠近页面底部的行间距错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59459495/

相关文章:

c++ - 协助在 MFC 中从多字节移植到 UNICODE

c++ - 如何使用整数数组作为 unordered_map 的键

c++ - 如何链接使用 MSVC 和 AddressSanitizer 编译的程序

C++/CX 工厂类提供具有相同数量参数的重载构造函数

C++ 模板,从 vc2005 移植到 2013

c++ - 使用MAP文件 VS2010 MFC

c++ - MFC 功能包错误?基于功能区的 GUI 在 hibernate ( sleep 模式)后不恢复

c++ - 如何使函数在C++中返回结构指针

c++ - 链接失败,并带有对libboost_thread的 undefined reference

mfc - 使用 CListCtrl,如何使选择颜色整行?