Ограничение длины строки в вызове PrintPreviewDialog для PrintDocument.PrintPage - PullRequest
0 голосов
/ 16 октября 2018

Использование VS Community 2017 с .NET Framework 4.6.

Следующий код был взят из документации MS и прекрасно работает для печати на принтере, но имеет ограничения в вызовах PrintPreviewDialog.

string text;
string ToPrint;
private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    int charactersOnPage = 0;
    int linesPerPage = 0;

    // Sets the value of charactersOnPage to the number of characters
    // of stringToPrint that will fit within the bounds of the page.
    e.Graphics.MeasureString(ToPrint, this.Font,
        e.MarginBounds.Size, StringFormat.GenericTypographic,
        out charactersOnPage, out linesPerPage);
    // Draws the string within the bounds of the page.
    e.Graphics.DrawString(ToPrint, this.Font, Brushes.Black,
        e.MarginBounds, StringFormat.GenericTypographic);

    // Remove the portion of the string that has been printed.
    ToPrint = ToPrint.Substring(charactersOnPage);

    // Check to see if more pages are to be printed.
    e.HasMorePages = (ToPrint.Length > 0);

    // If there are no more pages, reset the string to be printed.
    if (!e.HasMorePages)
        ToPrint = text;
}

После экспериментов я обнаружил, что e.Graphics.DrawString создает пустые страницы предварительного просмотра, если длина строки «ToPrint» превышает 32490 символов.

Кто-нибудь знает, почему это так?Есть какие-то настройки или опции, которые я пропускаю?

Спасибо

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