내 질문에 추가, 내가 이런 짓을 :
private string _previewWindowXaml =
@"<Window
xmlns ='http://schemas.microsoft.com/netfx/2007/xaml/presentation'
xmlns:x ='http://schemas.microsoft.com/winfx/2006/xaml'
Title ='Print Preview - @@TITLE'
Height ='200'
Width ='300'
WindowStartupLocation ='CenterOwner'>
<DocumentViewer Name='dv1'/>
</Window>";
internal void DoPreview(string title)
{
string fileName = System.IO.Path.GetRandomFileName();
FlowDocumentScrollViewer visual = (FlowDocumentScrollViewer)(_parent.FindName("fdsv1"));
try
{
// write the XPS document
using (XpsDocument doc = new XpsDocument(fileName, FileAccess.ReadWrite))
{
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
writer.Write(visual);
}
// Read the XPS document into a dynamically generated
// preview Window
using (XpsDocument doc = new XpsDocument(fileName, FileAccess.Read))
{
FixedDocumentSequence fds = doc.GetFixedDocumentSequence();
string s = _previewWindowXaml;
s = s.Replace("@@TITLE", title.Replace("'", "'"));
using (var reader = new System.Xml.XmlTextReader(new StringReader(s)))
{
Window preview = System.Windows.Markup.XamlReader.Load(reader) as Window;
DocumentViewer dv1 = LogicalTreeHelper.FindLogicalNode(preview, "dv1") as DocumentViewer;
dv1.Document = fds as IDocumentPaginatorSource;
preview.ShowDialog();
}
}
}
finally
{
if (File.Exists(fileName))
{
try
{
File.Delete(fileName);
}
catch
{
}
}
}
}
가 무엇을 : 그것은 실제로 XPS 문서에 시각의 내용을 인쇄합니다. 그런 다음 "인쇄 된"XPS 문서를로드하고 별도의 모듈이 아닌 문자열로 저장되는 매우 간단한 XAML 파일에 표시하고 런타임에 동적으로로드합니다. 결과 창에는 DocumentViewer 버튼이 있습니다 : 인쇄, 최대 페이지 폭 조정 등.
검색 상자를 숨기는 코드도 추가했습니다. 내가 어떻게했는지는 this answer to WPF: How can I remove the searchbox in a DocumentViewer?을 참조하십시오.
영향이 같다 :
alt text http://i48.tinypic.com/2hzkfat.jpg
XpsDocument는 ReachFramework DLL을 발견 할 수 있고, XpsDocumentWriter는 시스템에서 발견 될 수있다.dll을 모두 프로젝트에 대한 참조로 추가해야합니다.
안녕 Cheeso,이 대답은 http://stackoverflow.com/questions/584551/how-do-i-print-preview-when-using-a -documentpaginator-to-print/587962 # 587962 XpsDocument를 표준 창과 결합하여 사용할 것을 제안합니다 ... 이미 링크를 보았 기 때문에 대답으로 쓰고 싶지 않습니다. 단지를 위해서. 건배 :) – Anvaka