我正在try 创建一个使用.NET6WPF打印票证的程序.运行该程序后,文档将出现在打印队列中,但它只打印一张空白页.我也试过使用普通打印机,情况是一样的.
下面是我的测试.
第一个测试
FixedPage fixedPage = new FixedPage();
fixedPage.Width = 320;
fixedPage.Height = 267;
Style textStyle = new Style(typeof(TextBlock));
Setter sWeight = new Setter(TextBlock.FontWeightProperty, FontWeights.Bold);
textStyle.Setters.Add(sWeight);
Setter sFontColor = new Setter(TextBlock.ForegroundProperty, System.Windows.Media.Brushes.Black);
textStyle.Setters.Add(sFontColor);
TextBlock textBlock = new TextBlock();
textBlock.Text = content;
textBlock.FontSize = fontSize;
textBlock.Style = textStyle;
textBlock.FontFamily = new System.Windows.Media.FontFamily(fontFamily);
textBlock.SetValue(Canvas.LeftProperty, (double)x);
textBlock.SetValue(Canvas.TopProperty, (double)y);
fixedPage.Children.Add(textBlock);
PageContent pageContent = new PageContent();
((IAddChild)pageContent).AddChild(fixedPage);
FixedDocument fixedDocument = new FixedDocument();
fixedDocument.Pages.Add(pageContent);
PrintDialog printDialog = new PrintDialog();
printDialog.PrintDocument(fixedDocument.DocumentPaginator, "Ticket");
第二次测试.
FixedPage fixedPage = new FixedPage();
fixedPage.Width = 320;
fixedPage.Height = 267;
Style textStyle = new Style(typeof(TextBlock));
Setter sWeight = new Setter(TextBlock.FontWeightProperty, FontWeights.Bold);
textStyle.Setters.Add(sWeight);
Setter sFontColor = new Setter(TextBlock.ForegroundProperty, System.Windows.Media.Brushes.Black);
textStyle.Setters.Add(sFontColor);
TextBlock textBlock = new TextBlock();
textBlock.Text = content;
textBlock.FontSize = fontSize;
textBlock.Style = textStyle;
textBlock.FontFamily = new System.Windows.Media.FontFamily(fontFamily);
textBlock.SetValue(Canvas.LeftProperty, (double)x);
textBlock.SetValue(Canvas.TopProperty, (double)y);
fixedPage.Children.Add(textBlock);
PrintDialog printDialog = new PrintDialog();
printDialog.PrintVisual(fixedPage, "Ticket");
在打印机上,我可以在打印队列中看到一个名为‘Ticket’的项目,但没有内容.
我不需要任何打印机 Select 对话框;我想直接打印票证.我如何修改它以实现我的目标?