只是想知道是否有人试图入侵WPF DocumentViewer
以使其更有用.我已经花了差不多一个星期的时间,已经尝试根据我使用反射提取的方法为这个控件创建更强大的API.
每个人都知道如何通过反射从文档查看器中获取所选文本,但我的任务更复杂.选定的文本具有End
和Start
特性,这回ITextPointers
.我还有一个使用此代码提取的GlyphRuns集合.现在最后我想找出哪个包含选择开始. GlyphRun
所以我想知道如何转换ITextPointers
成GlyphRuns
反之亦然.我知道他们没有1:1的关系.这个控制与封闭的API和上周在Reflector花了不让我睡不好觉.我希望也许有人尝试过这样做或者看过代码示例,并且能够指导我完成这些丛林.
使用Wpf DocumentViewer控件我无法弄清楚当用户单击打印按钮时,如何在PrintDialog上设置DocumentViewer显示的PageOrientation.有没有办法搞定这个?
我的XAML代码是这样的:
<Window
xmlns ='http://schemas.microsoft.com/netfx/2007/xaml/presentation'
xmlns:x ='http://schemas.microsoft.com/winfx/2006/xaml'
Title ='Print Preview - More stuff here'
Height ='200'
Width ='300'
WindowStartupLocation ='CenterOwner'>
<DocumentViewer Name='dv1' ... />
</Window>
Run Code Online (Sandbox Code Playgroud)
如何在XAML或C#中删除搜索框?
我在文档查看器的查找框(作为搜索条件)中找到了这个.
什么应该匹配?
我正在开发一个打开并显示XPS文档的WPF应用程序.当应用程序关闭时,规范是应用程序应该删除打开的XPS文档以进行清理.但是,在打开某个XPS文档时,应用程序会在尝试删除该文件时抛出该文件仍在使用的异常.这有点奇怪,因为它只在打开特定的XPS文档时才会发生,并且只有在您超出第一页时才会发生.
我使用的一些代码如下所示:
要打开XPS文档:
DocumentViewer m_documentViewer = new DocumentViewer();
XpsDocument m_xpsDocument = new XpsDocument(xpsfilename, fileaccess);
m_documentViewer.Document = m_xpsDocument.GetFixedDocumentSequence();
m_xpsDocument.Close();
Run Code Online (Sandbox Code Playgroud)
用于导航XPS文档:
m_documentViewer.FirstPage();
m_documentViewer.LastPage();
m_documentViewer.PreviousPage();
m_documentViewer.NextPage();
Run Code Online (Sandbox Code Playgroud)
要关闭DocumentViewer对象并删除文件:
m_documentViewer.Document = null;
m_documentViewer = null;
File.Delete(xpsfilename);
Run Code Online (Sandbox Code Playgroud)
这一切都非常基础,它适用于我们测试的其他文档.但是对于特定的XPS文档,会弹出一个异常,说明要删除的文件仍在使用中.
我的代码有什么问题或遗漏吗?
谢谢!
在WPF DocumentViewer中显示XPS文件并关闭DocumentViewer实例后,XPS文件被锁定,我无法删除它.我需要释放XPS文件上的锁,以便我可以删除它,编写另一个具有相同名称的文件,并可选择在新的DocumentViewer实例中显示新的XPS文件.我需要在同一个应用程序实例中执行此操作 - 无需关闭应用程序(这是打印预览方案).
换句话说,如何在不在"File.Delete(tempXpsFile);"处抛出异常的情况下运行以下代码?声明?
var tempXpsFile = @"c:\path\to\Temporary.xps";
var previewWindow = new Window();
var docViewer = new DocumentViewer();
previewWindow.Content = docViewer;
GenerateXpsFile(tempXpsFile);
var xpsDocument = new XpsDocument(tempXpsFile);
previewWindow.ShowDialog();
File.Delete(tempXpsFile); //this will throw an exception due to a file lock on tempXpsFile
GenerateXpsFile(tempXpsFile); //assume this generates a different file
//otherwise the scenario doesn't make sense as we could just skip the above delete
//and this statement and re-use the same file
previewWindow = new Window();
docViewer = new DocumentViewer();
previewWindow.Content …
Run Code Online (Sandbox Code Playgroud) 当您尝试在XAML中构建一个Visual Studio时,Visual Studio会显示错误,这是一个众所周知的错误FixedDocument
.例如,以下代码段
<DocumentViewer>
<FixedDocument>
<PageContent>
<FixedPage Width="21.0cm" Height="29.7cm">
<TextBlock>Hello World!</TextBlock>
</FixedPage>
</PageContent>
</FixedDocument>
</DocumentViewer>
Run Code Online (Sandbox Code Playgroud)
编译并运行完美,但Visual Studio在错误列表中显示错误(Property 'Pages' does not support values of type 'PageContent'.
)这很烦人.
我正在寻找一种解决方案,允许我在Visual Studio中的XAML文件中构建我的文档,而不会收到该错误消息.我找到了一个解决方法,我想在下面分享作为答案,但我很好奇是否有一个更好(更优雅)的解决方案.
XpsDocument是从磁盘加载的
通过XpsDocument.GetFixedDocumentSequence方法()创建一个FixedDocumentSequence
通过DocumentViewer显示
想添加添加页眉和页脚打印
我不需要将页眉和页脚添加回XPS文档 - 仅打印输出
我尝试实现DocumentPaginator但无法使大小调整或放置工作
与FlowDocument的这个页脚不一样
我在那里使用FlowDocuments的解决方案就好了
将XAML流文档转换为带样式的XPS
在FixedDocumentSequence上,大小调整来自文档(我猜)
例如可以混合横向和纵向
我无法弄清楚如何挂钩到大小调整并为页眉和页脚腾出空间
我可以在其上标记一个标题但它超过顶部页面
和横向页面被切断
无法分配每页当它来自一个文档序列
作为链接说,它是建议的页面大小
DocumentPage .Size是只读
即使我使用DocumentPaginator.GetPage加载页面时创建我想要的大小的DocumentPage,然后大小被覆盖
更糟糕的是,DocumentPaginator似乎没有正确地意识到尺寸,因为它没有正确处理混合风景和肖像.风景是打印的肖像,只是在页面上运行.
有人问我发布代码
也可能是一个更简单更好的方法
看看页脚到FlowDocument如何使用它
这是它破坏
//这从GetPage获取页面大小 - 忽略上面的大小
public class DocumentPaginatorWrapperXPS : DocumentPaginator
{
System.Windows.Size m_PageSize;
System.Windows.Size m_Margin;
DocumentPaginator m_Paginator;
FixedDocumentSequence fixedDocumentSequence;
Typeface m_Typeface;
private string printHeader;
private int? sID;
private string docID;
public DocumentPaginatorWrapperXPS(FixedDocumentSequence FixedDocumentSequence, System.Windows.Size margin, string PrintHeader, …
Run Code Online (Sandbox Code Playgroud) .Net包含一个很好的控件DocumentViewer
.它还提供了一个子控件,用于在加载的文档中查找文本(至少它应该执行的操作).
当插入FixedPage
对象作为文档源时DocumentViewer
,查找功能只是找不到任何东西.甚至不是单个字母.我还没有尝试过FlowDocument
,因为文档DocumentViewer
没有那么有用,并且网上的资源实际上并不存在,我现在想问一下stackoverflow社区:
使WPF的Find-Function DocumentViewer
与FixedPage
文档一起工作需要什么?
[顺便说一句,我不使用自定义ControlTemplates
的DocumentViewer
]
我正在使用文档查看器和XPS atm,因为我之前没有尝试过.所以我有一段简单的代码加载XPS文档并在文档查看器中显示它,但是文档没有出现.文档查看器加载并在调试模式下快速一步,告诉我信息在那里,它只是不会显示.
dvDoc = new DocumentViewer();
string fileName = null;
string appPath = System.IO.Path.GetDirectoryName(Assembly.GetAssembly(typeof(DocumentWindow)).CodeBase);
if (type == "About")
fileName = appPath + @"\Documents\About.xps";
fileName = fileName.Remove(0, 6);
XpsDocument doc = new XpsDocument(fileName, FileAccess.Read);
dvDoc.Document = doc.GetFixedDocumentSequence();
Run Code Online (Sandbox Code Playgroud)
我能找到的所有文献都告诉我这样做,但它似乎对我不起作用.我知道文档查看器不喜欢URI,因此是filename.remove行.
关于我缺少什么的任何建议.
干杯,SumGuy
documentviewer ×10
wpf ×9
xps ×3
.net ×2
c# ×2
xpsdocument ×2
arabic ×1
criteria ×1
filelock ×1
fixedpage ×1
glyph ×1
printdialog ×1
search ×1
xaml ×1