gpt4 book ai didi

wpf - 为Wpf DocumentViewer PrintDialog设置PageOrientation

转载 作者:行者123 更新时间:2023-12-03 13:28:36 25 4
gpt4 key购买 nike

使用Wpf DocumentViewer控件,我无法弄清楚如何在用户单击打印按钮时在DocumentViewer显示的PrintDialog上设置PageOrientation。有没有办法迷上这个?

最佳答案

Mike's answer有效。我选择实现它的方法是创建自己的派生自DocumentViewer的文档查看器。另外,将Document属性转换为FixedDocument对我不起作用-转换为FixedDocumentSequence是可行的。

GetDesiredPageOrientation是您需要的任何内容。就我而言,我正在检查第一页的尺寸,因为我生成的文档的尺寸和方向对于文档中的所有页面都是一致的,并且序列中只有一个文档。

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Controls;
using System.Windows.Xps;
using System.Printing;
using System.Windows.Documents;

public class MyDocumentViewer : DocumentViewer
{
protected override void OnPrintCommand()
{
// get a print dialog, defaulted to default printer and default printer's preferences.
PrintDialog printDialog = new PrintDialog();
printDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue();
printDialog.PrintTicket = printDialog.PrintQueue.DefaultPrintTicket;

// get a reference to the FixedDocumentSequence for the viewer.
FixedDocumentSequence docSeq = this.Document as FixedDocumentSequence;

// set the default page orientation based on the desired output.
printDialog.PrintTicket.PageOrientation = GetDesiredPageOrientation(docSeq);

if (printDialog.ShowDialog() == true)
{
// set the print ticket for the document sequence and write it to the printer.
docSeq.PrintTicket = printDialog.PrintTicket;

XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(printDialog.PrintQueue);
writer.WriteAsync(docSeq, printDialog.PrintTicket);
}
}
}

关于wpf - 为Wpf DocumentViewer PrintDialog设置PageOrientation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1003585/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com