如何在Windows打印机的ONE页面中打印C#html文档? 我需要打印不同长度的帐单,它必须在一页。 但是在我的例子中,账单中有很多字符串,它与几页分开。
我用这个代码打印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;
但是在打印时它仍然会分成几页。 感谢