简体   繁体   English

.NET PrintDocument-文本被截断

[英].NET PrintDocument - Text gets cut off

I have an application (C#, .NET 3.5) that writes receipts. 我有一个写收据的应用程序(C#、. NET 3.5)。 They are usually printed with a small receipt printer with the .NET PrintDocument. 它们通常使用带有.NET PrintDocument的小型票据打印机进行打印。 The problem is the exception cases where I want to print with a regular printer. 问题是我想使用普通打印机进行打印的例外情况。 In these cases the text gets cut off. 在这些情况下,文本将被截断。 I wish to have a check or a switch to prevent this, but still keep the tight margins on the small printer. 我希望有一张支票或一个开关来防止这种情况,但仍要在小型打印机上留一点空白。

What would be the best way of dealing with this? 处理此问题的最佳方法是什么? Can I do this without touching the graphics generation? 我可以在不影响图形生成的情况下执行此操作吗?

Once you have set the Printer in PrintDocument, you might take a look at the present PaperSize using the value of: 在PrintDocument中设置打印机后,您可以使用以下值查看当前的PaperSize:

PrintDocument.PrinterSettings.DefaultPageSettings.PaperSize

Or maybe: 或者可能:

PrintDocument.PrinterSettings.PaperSizes

My issue was that I was setting the printerDocument.DefaultPageSettings.PaperSize. 我的问题是我正在设置printerDocument.DefaultPageSettings.PaperSize。

Instead, I recommend this 相反,我推荐这个

private PrintDocument _printDocument = new PrintDocument();
private int _checkPrint;
public Form1()
{
    InitializeComponent();
    _printDocument.BeginPrint += _printDocument_BeginPrint;
    _printDocument.PrintPage += _printDocument_PrintPage;
}

private void btnPrint_Click(object sender, EventArgs e)
{
    PrintDialog printDialog=new PrintDialog();
    if (printDialog.ShowDialog() == DialogResult.OK)
        _printDocument.Print();
}

private void _printDocument_PrintPage(object sender, PrintPageEventArgs e)
{
    // Print the content of RichTextBox. Store the last character printed.
    _checkPrint = rchEditor.Print(_checkPrint, rchEditor.TextLength, e);

    // Check for more pages
    e.HasMorePages = _checkPrint < rchEditor.TextLength;
}

private void _printDocument_BeginPrint(object sender, PrintEventArgs e)
{
    _checkPrint = 0;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM