gpt4 book ai didi

c# - WPF 如何将 FlowDocument BGImage 转换为 FixedDocument 并在 DocumentViewer 中显示?

转载 作者:太空宇宙 更新时间:2023-11-03 13:10:26 32 4
gpt4 key购买 nike

我有一个带有背景图像的 FlowDocument。目前它不能在 FlowDocumentReader 中正确显示,因为当文档上下滚动时背景图像保持居中。如何将这个FlowDocument转为FixedDocument,在DocumentViewer中显示,背景图也固定了?

我使用来自 here 的转换逻辑.但它不显示 FlowDocument.Background 图像。

    private FixedDocument convert(FlowDocument flowDocument)
{
if (flowDocument == null)
return null;
var paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;
var package = Package.Open(new MemoryStream(), FileMode.Create, FileAccess.ReadWrite);
var packUri = new Uri("pack://temp.xps");
PackageStore.RemovePackage(packUri);
PackageStore.AddPackage(packUri, package);
var xps = new XpsDocument(package, CompressionOption.NotCompressed, packUri.ToString());
XpsDocument.CreateXpsDocumentWriter(xps).Write(paginator);
FixedDocument doc = xps.GetFixedDocumentSequence().References[0].GetDocument(true);
return doc;
}

最佳答案

你写的

I have a FlowDocument with Background image. Currently it does not display properly in FlowDocumentReader since the background image stays centered when document is scrolled up and down.

不完全是您特定问题的答案,但要避免这种情况,请设置 ImageBrush.ViewportUnitsBrushMappingMode.Absolute .然后,设置 ImageBrush.Viewport到您的背景图像的所需尺寸:

        <FlowDocumentReader ViewingMode="Scroll">
<FlowDocument>
<FlowDocument.Background>
<ImageBrush TileMode="Tile" Stretch="Fill" Viewport="0,0,1000,400" ViewportUnits="Absolute">
<ImageBrush.ImageSource>
<!--Image source here...-->
</ImageBrush.ImageSource>
</ImageBrush>

可选择设置ImageBrush.StretchStretch.Fill用你的图像填充你指定的视口(viewport),并设置ImageBrush.TileModeTileMode.Tile使背景图像重复。

关于c# - WPF 如何将 FlowDocument BGImage 转换为 FixedDocument 并在 DocumentViewer 中显示?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29021961/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com