Страница обрезается во время печати с помощью html-файла элемента управления Windows.Forms.WebBrowser для почтовой квитанции - PullRequest
0 голосов
/ 22 октября 2018

У меня проблемы с тем, чтобы избежать разрыва страницы в моей распечатке бланка приложения Windows Form. Во время печати сначала нажимаю кнопку «Печать», затем генерирую файл HTML, а затем печатаю этот файл 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>

.страница после определенной высоты

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...