繁体   English   中英

将FixedDocument添加并显示为WPF表单

[英]Add and display FixedDocument to WPF form

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

这是一个初学者的问题。 我不熟悉WPF。 我查看了MSDN / Goog。 网站假设我已经添加了FixedDocument并且只需要操作它。

我有:

    private FixedDocument CreateFixedDocumentWithPages()
    {            
        FixedDocument fixedDocument = CreateFixedDocument();
        fixedDocument.DocumentPaginator.PageSize = size;            

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

        return fixedDocument;
    }

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

for show FixedDocument:

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

对于ActualWidth pb:

我认为你应该为每个FixedPage调用方法Measure&Arrange。

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

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

所以我的情况略有不同,但这个答案让我很接近。 我正在使用固定文档从扫描仪显示Tiff。 其中一些Tiff可以采用法律信件格式(比标准A4 8.5比11尺寸长)。 下面的代码解决了我的问题,这个答案有所帮助。

所以我最终得到了一个固定的文档,创建了一个页面内容,创建了一个固定页面,创建了一个图像。

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

            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;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM