【发布时间】:2020-06-04 15:24:02
【问题描述】:
我通过将FixedPages 添加到PageContents 来创建FixedDocument,然后以某种方式将它们添加到FixedDocument
FixedDocument fd = new FixedDocument();
// add FixedPages in PageContent to fd
用PrintDialog 打印它们,像这样
pdialog.PrintDocument(fd.DocumentPaginator, "Test");
产生正确的页数。但是,打印的每一页 - 例如到 PDF - 是第一页的内容。
我尝试测试添加到FixedPages 的ImageSources,这些似乎是正确的。我还用DocumentViewer 测试了最终的FixedDocument,就像这样
Window wnd = new Window();
DocumentViewer viewer = new DocumentViewer();
viewer.Document = fd;
wnd.Content = viewer;
try
{
wnd.Show();
}
catch(Exception e)
{
Console.WriteLine(e.ToString());
}
这奇怪地显示了我期望的正确输出。更奇怪的是,我在wnd.Show(); 之后得到了一个IOException(这就是我用try/catch 包围它的原因)。即使使用try catch,我也只能在MainWindow 抛出的相同IOException 之前1-2 秒查看它。诸如“错误的用户名或密码”之类的东西 - 这没有意义,因为我要打印的图像是本地图像。
把DocumentViewer放在一边,我对Print()方法的问题只打印第一页n次(n是它应该是的实际页数)仍然存在,只是认为DocumentViewer中的异常可能会让某人了解潜在的问题。
这可能与 FixedDocument always print first page 重复 - 但是他没有提到 DocumentViewer 的问题,并且问题仍未得到解答。
提前感谢您的帮助!
【问题讨论】:
-
如果您能提供一个可重现的示例供我测试,我或许可以帮助调试。
-
@Keith Stein 感谢您的回复,但至少我找到了根本问题(请参阅下面的答案),而不是为什么会发生这种情况。
标签: c# wpf printing fixeddocument