首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >横向的WPF到XPS

横向的WPF到XPS
EN

Stack Overflow用户
提问于 2010-03-22 23:02:32
回答 1查看 8.9K关注 0票数 12

我正在尝试从WPF控件生成XPS文档。到目前为止,打印工作正常,但我找不到在横向模式下创建XPS的方法。

我创建XPS文件的代码主要取自另一个SO页面

代码语言:javascript
复制
    public FixedDocument ReturnFixedDoc()
    {
        FixedDocument fixedDoc = new FixedDocument();
        PageContent pageContent = new PageContent();
        FixedPage fixedPage = new FixedPage();

        var ctrl = new controlToPrint();

        //Create first page of document
        fixedPage.Children.Add(ctrl);
        ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage);
        fixedDoc.Pages.Add(pageContent);
        //Create any other required pages here

        return fixedDoc;
    }


    public void SaveCurrentDocument()
    {
        // Configure save file dialog box
        Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
        dlg.FileName = "MyReport"; // Default file name
        dlg.DefaultExt = ".xps"; // Default file extension
        dlg.Filter = "XPS Documents (.xps)|*.xps"; // Filter files by extension

        // Show save file dialog box
        Nullable<bool> result = dlg.ShowDialog();

        // Process save file dialog box results
        if (result == true)
        {
            // Save document
            string filename = dlg.FileName;

            FixedDocument doc = ReturnFixedDoc();
            XpsDocument xpsd = new XpsDocument(filename, FileAccess.Write);
            System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
            xw.Write(doc);
            xpsd.Close();
        }
    }

任何帮助都是非常感谢的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-03-24 05:40:19

尝试在ReturnFixedDoc中设置FixedPage的大小:

代码语言:javascript
复制
// hard coded for A4
fixedPage.Width = 11.69 * 96;
fixedPage.Height = 8.27 * 96;

数字的形式为(英寸)x(每英寸点数)。96是WPF的DPI。我已经使用了A4页面的大小。

票数 13
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2493244

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档