我目前正在尝试使用PrintFixedDocument打印内容容器(它只包含带有信息的datagrids)和图像的内容。它完美打印在我的机器(Windows 10)上,具有完整的图像质量,而在另一台Windows 8上,质量相同。PrintFixedDocument wpf打印质量 - Windows 10/8与Windows 7
但是,如果在Windows 7 PC上完成此操作,则图像质量变得非常差,最终结果非常模糊。这是一个问题,因为计算机无法从各种原因的Windows 7更新,所以即时通讯想知道是否有其他人经历过,如果有的话是否有解决方法?也可能是我的GetFixedDocument
方法的问题,虽然我不能明白为什么这会工作两个赢得10和8,但不是7
注这是运行从应用程序的安装版本上的每个PC
也尝试上有多台打印机在所有3级的操作系统
任何帮助,将不胜感激
的XAML:
<StackPanel Margin="-105,146,66,0" Height="900" VerticalAlignment="Top" x:Name="PrintImageContextMenu">
<Image Canvas.ZIndex="0" Source="{Binding Coupon.OverlayImagePath}" Margin="0,-21,-76,108" Stretch="Fill" />
<ContentControl Content="{Binding}" ContentTemplateSelector="{StaticResource DataViewerDataTemplateSelector}" />
</StackPanel>
C#: 公共部分类CouponViewerView { 公共CouponViewerView() { 的InitializeComponent(); }
public void Print()
{
//Executes On Thread
Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, (EventHandler)delegate
{
UpdateLayout();
var fixedDoc = PrintHelper.GetFixedDocument(StackPanelToPrint, new PrintDialog());
PrintHelper.ShowPrintPreview(fixedDoc);
}, null, null);
}
private void PrintCurrentForm(object sender, RoutedEventArgs e)
{
Print();
}
C#打印助手代码:
public static void ShowPrintPreview(FixedDocument fixedDoc)
{
var wnd = new Window();
var viewer = new DocumentViewer();
viewer.Document = fixedDoc;
wnd.Content = viewer;
wnd.ShowDialog();
}
public static FixedDocument GetFixedDocument(FrameworkElement toPrint, PrintDialog printDialog)
{
var capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);
var pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
var visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
var fixedDoc = new FixedDocument();
//If the toPrint visual is not displayed on screen we neeed to measure and arrange it
toPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
toPrint.Arrange(new Rect(new Point(0, 0), toPrint.DesiredSize));
//
var size = toPrint.DesiredSize;
//Will assume for simplicity the control fits horizontally on the page
double yOffset = 0;
while (yOffset < size.Height)
{
var vb = new VisualBrush(toPrint)
{
Stretch = Stretch.None,
AlignmentX = AlignmentX.Left,
AlignmentY = AlignmentY.Top,
ViewboxUnits = BrushMappingMode.Absolute,
TileMode = TileMode.None,
Viewbox = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height)
};
var pageContent = new PageContent();
var page = new FixedPage();
((IAddChild)pageContent).AddChild(page);
fixedDoc.Pages.Add(pageContent);
page.Width = pageSize.Width;
page.Height = pageSize.Height;
var canvas = new Canvas();
FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
canvas.Width = visibleSize.Width;
canvas.Height = visibleSize.Height;
canvas.Background = vb;
page.Children.Add(canvas);
yOffset += visibleSize.Height;
}
return fixedDoc;
}
即使我确定你可能已经检查过,但只是为了咯咯地笑。你是否检查过win7机器上的设置,以确保它不是在草稿模式下打印或进行任何手动调整大小等,以及确保任何打印驱动程序是最新的? –
有消除了所有常见的嫌疑人。在所有打印机上打印质量良好,所有驱动程序都是最新的。它真的很奇怪,因为从来没有见过类似的东西。 – philmckendry
是的,我知道他们对驱动程序包和一些东西进行了一些更改,试图让制造商停止加载一堆OEM bloatware废话,但据我所知,它应该都采用相同的方式,无论操作系统版本。这很有趣。 –