WPF报表在XPS中输出的自定义页面大小 [英] Custom page size output in XPS from WPF report

查看:178
本文介绍了WPF报表在XPS中输出的自定义页面大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果将输出发送到打印机(物理或虚拟打印机,例如PDFCreator),我有一个WPF报表,该报表以自定义页面大小绘制报表内容(我们可以将其视为A4,问题是相同的).自定义页面大小为每个页面正确保留.

I have a WPF report which draws the report content in a custom page size (we can consider it as a A4, the problem is the same), if I send the output to a printer (physical or virtual like PDFCreator) my custom page size are correctly preserved for each page.

但是当我将其输出为XPS格式时,页面将适应Letter页面的大小.

But when I output it as XPS format the pages are adapted to Letter page size.

在将WPF报告输出到XPS时,如何保留我的自定义页面大小?

How to preserve my custom page size when outputting a WPF report to XPS ?

我的最终目标:是从WPF获得PDF,而我的方法是使用PDFSharper将XPS转换为PDF.转换效果很好,但是XPS输出破坏了我的自定义页面大小.欢迎使用其他方法,但是无论如何,我想了解和控制XPS输出页面的大小.

MY FINAL GOAL: Is to have a PDF from WPF, and my approach is to convert a XPS to PDF using PDFSharper. The conversion works well but the XPS output corrupts my custom page size. Others approaches are welcome but I would like to understand and control the XPS output page size, anyway.

示例项目: Test_WpfToPDF_withXpsCorruptingPageSizeToLetter.zip

推荐答案

当您将用户控件(报表)包装在另一个元素中时,它似乎可以工作,而且还提供了实际大小,并且不要忘记放置背景. 我不知道为什么,但是背景和大小似乎可以解决问题.

It seems to work when you wrap the user control (the report) inside another element, providing also the real size and not forgetting to put a background. I don't know exactly why, but the background seems to do the trick, along with the size.

public override DocumentPage GetPage(int pageNumber) {
    var page = new MyUserControl();

    Border wrapper = new Border();
    wrapper.Width = this.PageSize.Width;
    wrapper.Height = this.PageSize.Height;
    wrapper.Background = Brushes.White;

    wrapper.Child = page;

    wrapper.Measure(this.PageSize);
    wrapper.Arrange(new Rect(new Point(0, 0), this.PageSize));
    wrapper.UpdateLayout();

    return new DocumentPage(wrapper);
}

这篇关于WPF报表在XPS中输出的自定义页面大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆