WPF 簡単文書表示/XPS
WPF簡単文書表示
Xamlを使って簡単に文書表示ウインドウを作る。主要なものは下記の3点。
使用する文書ファイルはXPS形式。MicroSoft版のPDFの様な もの。Wordで保存できる。また、プリンタとしてXPS Writerを選べば、印刷時にXPSに変換できる。文書の型はFixedDocument。表示はDocumentViewer。
早速Xaml
Xaml
DocumentViewerをStackPanelに配置しただけ。
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Document" Width="100" Height="100"> <StackPanel> <DocumentViewer Name="docViewer" /> </StackPanel> </Window>
コード
DocumentViewerのDocumentに読んだ文書を設定。
private void LoadFileToDocumentViewer(string filename)
{
XpsDocument document = new XpsDocument(filename, FileAccess.Read, CompressionOption.NotCompressed);
FixedDocumentSequence sequence = document.GetFixedDocumentSequence();
docViewer.Document = sequence as IDocumentPaginatorSource;
}
型など
- System.Windows.Documents.IDocumentPaginatorSource
- System.io.FileAccess
- System.io.Packaging.CompressionOption
- System.Windows.xps.Packaging.XpsDocument (ReachFramework)
- System.Windows.Controls.DocumentViewer
参考
http://www.balard.sakura.ne.jp/vb/wpf/documentviewer.php
Msdn DocumentViewer class
https://msdn.microsoft.com/ja-jp/library/system.windows.controls.documentviewer(v=vs.110).aspx
サンプル
http://www.kanazawa-net.ne.jp/~pmansato/xps/xps_viewer.htm
http://office-qa.com/Word/wd184.htm
StackOverFlow
http://stackoverflow.com/questions/5116465/integrating-help-in-a-wpf-application
http://www.balard.sakura.ne.jp/vb/wpf/documentviewer.php
PDFViewer
https://codezine.jp/article/detail/7543
xpsdocument
https://msdn.microsoft.com/ja-jp/library/system.windows.xps.packaging.xpsdocument(v=vs.110).aspx
new-object