使用Windows.Forms.WebBrowser控件html文件进行pos滑行打印时页面被切开

时间:2018-10-22 11:23:28

标签: c# winforms

为了避免在Windows窗体应用程序零售单据上出现分页符,我遇到了麻烦, 在打印单击按钮时,我首先生成HTML文件,然后在打印后使用Web浏览器控件生成HTML文件。 我试图更改注册表设置,但可以避免页面剪切,如何停止页面剪切。

public void Print_Cash_sales()
    {


       var dir = @"D:\study\myslip.html";  // file location



       // MessageBox.Show(dir.ToString());



        //return;
        // Create a WebBrowser instance. 
        WebBrowser webBrowserForPrinting = new WebBrowser();

        // Add an event handler that prints the document after it loads.
        webBrowserForPrinting.DocumentCompleted +=
            new WebBrowserDocumentCompletedEventHandler(myWebBrowser_DocumentCompleted);

        // Set the Url property to load the document.
        webBrowserForPrinting.Url = new Uri(dir);



    }

public static void myWebBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        string pageSetupKey = "Software\\Microsoft\\Internet Explorer\\PageSetup";
        bool isWritable = true;
        string height = "1000";
        RegistryKey rKey = Registry.CurrentUser.OpenSubKey(pageSetupKey, isWritable);

        rKey.SetValue("margin_bottom", 0.10);
        rKey.SetValue("margin_left", 0.10);
        rKey.SetValue("margin_right", 0.10);
        rKey.SetValue("margin_top", 0.10);
        rKey.SetValue("footer", "");
        rKey.SetValue("header", "");
        rKey.SetValue("Print_Background", "yes");
        rKey.SetValue("SizeHeight", height.ToString(), Microsoft.Win32.RegistryValueKind.String);


        // Print the document now that it is fully loaded.
        ((WebBrowser)sender).Print();

        // Dispose the WebBrowser now that the task is complete. 
        ((WebBrowser)sender).Dispose();

        // myWebBrowser.ShowPrintPreviewDialog();
        // myWebBrowser.Print();
        rKey.SetValue("Print_Background", "no");

    }

这是html文件代码

    <!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test</title>
<style>

@media print
{
  table { page-break-after:avoid;page-break-inside:avoid; }
  tr    { page-break-inside:avoid; page-break-after:avoid }
  td    { page-break-inside:avoid; page-break-after:avoid }
  thead { display:table-header-group }
  tfoot { display:table-footer-group }
}


</style>
</head>
<body>
<table width='100px' border='0' cellpadding='0' cellspacing='0' style='font-size: 13px;font-family: Verdana'>
<tr>
<td colspan='3' style='text-align:center;'>-:TAX INVOICE:-</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >KADIWALA TRADERS CC</td>
</tr>
<tr>
<td colspan='3' >23,DANIE JOUBERT STREET,</td>
</tr>
<tr>
<td colspan='3' >TZANEEN-0850</td>
</tr>
<tr>
<td colspan='3' >REG NO.: 2009/213447/23</td>
</tr>
<tr>
<td colspan='3' >VAT NO.: 4600275061</td>
</tr>
<tr>
<td colspan='3' >PHONE: +27</td>
</tr>
<tr>
<td colspan='3' >EMAIL: PRABHU@COMPUTERSATALL.CO.ZA</td>
</tr>
<tr>
<td colspan='3' >TILL NO.: 1</td>
</tr>
<tr>
<td colspan='3' >DATE: 10/20/2018 2:12:40 PM</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >Stock Code: FZL</td>
</tr>
<tr>
<td colspan='3' >1</td>
</tr>
<tr>
<td colspan='3'>1 x 100     15%  =  100</td>
</tr>
<tr>
<td colspan='3' >Stock Code: FZL</td>
</tr>
<tr>
<td colspan='3' >1</td>
</tr>
<tr>
<td colspan='3'>1 x 100     15%  =  100</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >Stock Code: FZL</td>
</tr>
<tr>
<td colspan='3' >1</td>
</tr>
<tr>
<td colspan='3'>1 x 100     15%  =  100</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >Stock Code: FZL</td>
</tr>
<tr>
<td colspan='3' >1</td>
</tr>
<tr>
<td colspan='3'>1 x 100     15%  =  100</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >Stock Code: FZL</td>
</tr>
<tr>
<td colspan='3' >1</td>
</tr>
<tr>
<td colspan='3'>1 x 100     15%  =  100</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >Stock Code: FZL15</td>
</tr>
<tr>
<td colspan='3' >GGGG</td>
</tr>
<tr>
<td colspan='3'>1 x 1000     15%  =  1000</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' style='text-align:center'>-:Payment Detail:-</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3'>CASH ==>R. 1500.000</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' style='text-align:center;'>-:CASH SALES:-</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >F</td>
</tr>
<tr>
<td colspan='3' >INV NO.: DCI-10000</td>
</tr>
<tr>
<td colspan='3' ><span >INV AMOUNT.: 1100.000</span></td>
</tr>
<tr>
<td colspan='3' >TOTAL VAT: 10001</td>
</tr>
<tr>
<td colspan='3' >TOTAL ITEMS: 2</td>
</tr>
<tr>
<td colspan='3' >TENDERED: 1500.000</td>
</tr>
<tr>
<td colspan='3' >CHANGE: 400.000</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>
<tr>
<td colspan='3' >DEAR CUSTOMER, THANK YOU FOR YOUR BUSINESS</td>
</tr>
<tr>
<td colspan='3' ><hr style='border:1px solid #000'></td>
</tr>

</table>
    </body>
</html>

here is image printer cuts the page after certain height

0 个答案:

没有答案