No Margin Printing

I am trying to print a WPF 4 "3" height control.

I used ScaleTransform for a control (a Canvas ) to scale it; however, when I print to the printer, part of the image is cropped (top and left edges).

According to this thread :

The cause of this problem is because the printer provides a non-print margin along the edge of the paper, but the PrintDialog.PrintVisual method PrintDialog.PrintVisual designed to print on the edge of the sheet. Thus, the area lying in the unsealed edge around the edge of the paper is trimmed.

The thread does not mention how to retrieve fields or how to make the printer ignore these fields. How to get these values ​​so that I can print using WPF without cropping?

+4
source share
1 answer

You need to combine the information from PrintDocumentImageableArea with the members Measure and Arrange on the 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 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 } 
+5
source

Source: https://habr.com/ru/post/1401055/


All Articles