如何批量打印多个flowdocument? 以下代码应打印不同的文档但打印相同。只有在打印到xps打印机时,此示例才能正常工作。
var printDialog = new PrintDialog();
if(printDialog.ShowDialog() == true) {
var xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
foreach(var person in persons) {
var doc = Application.LoadComponent(new Uri("Template.xaml", UriKind.Relative)) as FlowDocument;
doc.DataContext = persons;
var paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;
xpsDocumentWriter.Write(paginator);
}
}
答案 0 :(得分:1)
这些是线程问题。分配DataContext
后,确保线程处理其等待队列:
Dispatcher.CurrentDispatcher.Invoke(
DispatcherPriority.SystemIdle, new DispatcherOperationCallback(_ => null), null);