我正在使用WPF PrintVisual方法来打印对象。检查下面的代码。
PrintDialog dialog = new PrintDialog();
System.Printing.PrintCapabilities capabilities = dialog.PrintQueue.GetPrintCapabilities(dialog.PrintTicket);
Double height = dialog.PrintableAreaHeight;
Double width = dialog.PrintableAreaWidth;
myObj.Measure(new Size(width, height));
myObj.Arrange(new Rect(new Point((capabilities.PageImageableArea.OriginWidth), (capabilities.PageImageableArea.OriginHeight)), new Size(width, height)));
dialog.PrintVisual(myObj, "Print in WPF with fit to printing page");
如果我用xps打印它,它的效果非常好。但是当我在纸上打印(A4 => 8.5 x 11英寸)时,对象会从右侧剪切,因为它会在纸张的左侧生成边距。任何人都可以告诉我如何在纸上避免这个边距并打印物体全长?
由于
答案 0 :(得分:1)
您使用dialog.PrintableAreaHeight
和dialog.PrintableAreaWidth
作为可打印尺寸非常可疑,但capabilities.PageImageableArea
表示可打印尺寸。这些是不相关的测量;尝试使用
new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight)
在myObj.Measure
和myObj.Arrange
。