Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print With No Margin

Tags:

printing

wpf

I am attempting to print a WPF control 4" tall by 3" wide.

I have used a ScaleTransform on the control (a Canvas) to scale it accordingly; however, when I print to a printer part of the image is cut off (the top and left edges).

According to this thread:

The reason of this problem is that the printer provides an unprinted margin around the edge of the paper, but the PrintDialog.PrintVisual method intends to print to the edge of the paper. So the area that lies in the unprinted margin around the edge of the paper is clipped.

The thread fails to mention how to retrieve the margins or how to force the printer to ignore these margins. How do I obtain these values so that I can print using WPF without clipping?

like image 443
Frinavale Avatar asked Mar 12 '12 20:03

Frinavale


People also ask

Can you print something with no margins?

From the File menu, choose "Page Setup" and then set all of your margins to zero. Your document will print across the full width of the paper, as long as your printer's settings are set similarly.

Can my printer print borderless?

If you have a printer that supports borderless printing, you can find the borderless printing option from the printer or print properties window that appears when you are printing an image. Many newer inkjet printers allow for borderless printing.


1 Answers

You'll need to combine information from the PrintDocumentImageableArea with the Measure and Arrange members on your UIElement:

// I could not find another way to change the margins other than the dialog
var result = printDialog.ShowDialog();
if (result.HasValue && result.Value)
{
    var queue = printDialog.PrintQueue;

    // Contains extents and offsets
    var area = queue.GetPrintCapabilities(printDialog.PrintTicket)
                    .PageImageableArea;

    // scale = area.ExtentWidth and area.ExtentHeight and your UIElement's bounds
    // margin = area.OriginWidth and area.OriginHeight
    // 1. Use the scale in your ScaleTransform
    // 2. Use the margin and extent information to Measure and Arrange
    // 3. Print the visual
}
like image 100
user7116 Avatar answered Sep 19 '22 22:09

user7116