LocalPrintServer localPrintServer = new LocalPrintServer();
var pqs = localPrintServer.GetPrintQueues();
var xpspq = pqs.FirstOrDefault(p => p.Name == "Microsoft Print to PDF");
var pt = xpspq.DefaultPrintTicket;
var pc = xpspq.GetPrintCapabilities();
//逐份打印
//if (pc.CollationCapability.Contains(Collation.Collated)) pt.Collation = Collation.Collated;
//长边翻转的双面打印
//if (pc.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge)) pt.Duplexing = Duplexing.TwoSidedLongEdge;
//沿着左边缘进行两次装订
//if (pc.StaplingCapability.Contains(Stapling.StapleDualLeft)) pt.Stapling = Stapling.StapleDualLeft;
//正序倒序
//pt.PageOrder = PageOrder.Standard;
pt.PageMediaSize = new PageMediaSize(100, 100);
//pt.PageOrientation = PageOrientation.ReverseLandscape;
//var result = xpspq.MergeAndValidatePrintTicket(xpspq.UserPrintTicket,pt);
xpspq.DefaultPrintTicket = pt;
//xpspq.Commit();
var xpsdw = PrintQueue.CreateXpsDocumentWriter(xpspq);
var sp = new StackPanel();
sp.Children.Add(new TextBlock() { Text = "1111111111", FontSize = 28 });
sp.Children.Add(new TextBlock() { Text = "2222222222", FontSize = 28 });
//打印窗口中的visual时,PageMediaSize 不起作用,起作用的是容器(这里是grid) 的width和height
//grid.Children.Remove(sp);
xpsdw.WriteAsync(sp, pt);
//grid.Children.Add(sp);
//xpsdw.Write(new TextBlock() { Text = "test xpsdocumentwrite" });