首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向WPF表单中添加和显示FixedDocument

向WPF表单中添加和显示FixedDocument
EN

Stack Overflow用户
提问于 2013-10-07 16:28:35
回答 2查看 4.4K关注 0票数 1

我正在以编程方式生成一个FixedDocument来帮助我打印。FixedDocument.ActualWidth将以0的身份出现。我怀疑这是因为我实际上并没有显示FixedDocument。如何添加和显示FixedDocument对象?

这是个初学者的问题。我对WPF不在行。我看了MSDN/Goog。站点假设我已经添加了FixedDocument,只需要对它进行操作。

我有:

代码语言:javascript
复制
    private FixedDocument CreateFixedDocumentWithPages()
    {            
        FixedDocument fixedDocument = CreateFixedDocument();
        fixedDocument.DocumentPaginator.PageSize = size;            

        PageContent content = AddContentFromImage();
        fixedDocument.Pages.Add(content);

        return fixedDocument;
    }

我想要的伪代码:myWpfFormObject.AddChild(fixedDocument)

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-10-07 16:34:58

for show FixedDocument:

在Wpf窗口中添加DocumentViewer控件,然后设置Document属性。

for ActualWidth pb:

我认为您应该将方法称为度量衡&为每个FixedPage进行安排。

请参阅msdn中exapmle中的以下代码

代码语言:javascript
复制
Size sz = new Size(8.5 * 96, 11 * 96);
fixedPage.Measure(sz);
fixedPage.Arrange(new Rect(new Point(), sz));
fixedPage.UpdateLayout();

另见https://stackoverflow.com/a/1695518/1271037

票数 3
EN

Stack Overflow用户

发布于 2016-11-17 16:15:35

所以我遇到了一个稍微不同的情况,但这个答案让我接近了。我用固定文档显示扫描仪上的数据。其中一些可以采用合法的信函格式(比标准的A4 8.5长11倍)。下面的代码解决了我的问题,这个答案很有帮助。

最后,我拿一个固定的文档,创建一个页面内容,创建一个固定的页面,创建一个图像。

然后获取图像并将其添加到固定页面,然后将固定页面添加到页面内容中,然后获取页面内容并将其添加到固定文档中。

代码语言:javascript
复制
            System.Windows.Documents.FixedPage fixedPage = new System.Windows.Documents.FixedPage();

            System.Windows.Documents.PageContent pageContent = new System.Windows.Documents.PageContent();
            pageContent.Child = fixedPage;
            if (fixedDocument == null)
            {
                fixedDocument = new System.Windows.Documents.FixedDocument();
            }
            fixedDocument.Pages.Add(pageContent);


            System.Windows.Controls.Image image = new System.Windows.Controls.Image();

            TiffBitmapDecoder decoder = new TiffBitmapDecoder(new Uri(tiffImage, UriKind.Relative), BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnDemand);
            image.Source = decoder.Frames[0];

            fixedPage.Children.Add(image);

            //Code to make the legal letter size work.
            Size sz = new Size(decoder.Frames[0].Width, decoder.Frames[0].Height);
            fixedPage.Width = sz.Width;
            fixedPage.Height = sz.Height;

            pageContent.Width = sz.Width;
            pageContent.Height = sz.Height;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19229941

复制
相关文章

相似问题

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