Search code examples
c#winformsprintingprintdialog

Print Fit To Page


I need to print a label to fit the page. I'm tryng this but print big than page, width and height seems to be to much

private void PrinterPrintPage(object sender, PrintPageEventArgs e)
{
    var b = Tasks.Pop();

    if (b.Label == null) 
        b.Label = GetLabelImage(b.Codice, b.ColoreID);

    var rect = e.PageBounds;
    e.Graphics.DrawImage(b.Label, rect);
    e.HasMorePages = Tasks.ContainTasks();

    _printedCount++;
}

Solution

  • As per MSDNs documentation on PrintPageEventArgs.PageBounds,

    Most printers cannot print at the very edge of the page.

    ...first of all, try changing PageBounds to MarginBounds. If this doesn't help, "deflate" the bounds rectangle towards the centre of the page so you move away from the edges.