Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在一页中打印C#html文档_C#_Html_Printing - Fatal编程技术网

如何在一页中打印C#html文档

如何在一页中打印C#html文档,c#,html,printing,C#,Html,Printing,如何在windows打印机上一页打印C#html文档? 我需要打印不同长度的账单,而且必须是一页。 但在我的例子中,bill中有很多字符串,它是独立的,只有几页 我正在使用以下示例代码打印html: private void PrintHelpPage() { // Create a WebBrowser instance. WebBrowser webBrowserForPrinting = new WebBrowser(); // Add an event han

如何在windows打印机上一页打印C#html文档? 我需要打印不同长度的账单,而且必须是一页。 但在我的例子中,bill中有很多字符串,它是独立的,只有几页

我正在使用以下示例代码打印html:

private void PrintHelpPage()
{
    // Create a WebBrowser instance. 
    WebBrowser webBrowserForPrinting = new WebBrowser();

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

    // Set the Url property to load the document.
    webBrowserForPrinting.Url = new Uri(@"\\myshare\bill.html");
}

private void PrintDocument(object sender,
    WebBrowserDocumentCompletedEventArgs e)
{
    // Print the document now that it is fully loaded.
    ((WebBrowser)sender).Print();

    // Dispose the WebBrowser now that the task is complete. 
    ((WebBrowser)sender).Dispose();
}
我知道如何从WebBrowser控件读取页面的高度 wb.Document.Body.ScrollRectangle.Height

并尝试通过几种不同的方式更改页面的维度:

PrintDocument pd = new PrintDocument();
PaperSize pkCustomSize1 = new PaperSize("First custom size", 310, 250);

pd.DefaultPageSettings.PaperSize = pkCustomSize1;
System.Drawing.Printing.PaperSize("Custom Paper Size", 250, 550);

pd.SDefaultPageSettings.PaperSize.Kind = PaperKind.Custom;
pd.DefaultPageSettings.PaperSize.Height = 1633;
但在打印时,它仍然会分成几页。
谢谢

我在这里找到了解决方案
使用P/Invoke更改打印机设置的助手类。

我正在卷筒纸上打印,所以页面长度是可变的。