我正在以编程方式生成一个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)
发布于 2013-10-07 16:34:58
for show FixedDocument:
在Wpf窗口中添加DocumentViewer控件,然后设置Document属性。
for ActualWidth pb:
我认为您应该将方法称为度量衡&为每个FixedPage进行安排。
请参阅msdn中exapmle中的以下代码
Size sz = new Size(8.5 * 96, 11 * 96);
fixedPage.Measure(sz);
fixedPage.Arrange(new Rect(new Point(), sz));
fixedPage.UpdateLayout();发布于 2016-11-17 16:15:35
所以我遇到了一个稍微不同的情况,但这个答案让我接近了。我用固定文档显示扫描仪上的数据。其中一些可以采用合法的信函格式(比标准的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;https://stackoverflow.com/questions/19229941
复制相似问题