/// <summary> /// Create a new instance of the document viewer, open the xps document, and navigate to the /// designated page. /// </summary> private void ShowHelp() { xpsDocumentViewer = new XPSDocumentViewer(); System.Windows.Xps.Packaging.XpsDocument xpsDoc = new System.Windows.Xps.Packaging.XpsDocument(_env.strAppDir + "\\Help\\" + _strXPSFile, System.IO.FileAccess.Read); xpsDocumentViewer.xpsViewer1.Document = xpsDoc.GetFixedDocumentSequence(); xpsDocumentViewer.ReferenceHelp = this; m_intCurrentPageNumber = PageNumber; System.Windows.Documents.DocumentPage oPage = xpsDocumentViewer.xpsViewer1.Document.DocumentPaginator.GetPage(PageNumber); xpsDocumentViewer.xpsViewer1.GoToPage(PageNumber); xpsDocumentViewer.WindowState = WindowState.Normal; xpsDocumentViewer.Top = frmMain.g_oFrmMain.Top; xpsDocumentViewer.Height = frmMain.g_oFrmMain.ClientSize.Height; xpsDocumentViewer.WindowStartupLocation = WindowStartupLocation.CenterScreen; xpsDocumentViewer.IsEnabled = true; xpsDocumentViewer.Visibility = Visibility.Visible; m_oXpsDocument = xpsDoc; xpsDocumentViewer.ShowDialog(); }
public HelpPage() { InitializeComponent(); var doc = new System.Windows.Xps.Packaging.XpsDocument(Environment.CurrentDirectory + "\\X758Helps.xps", System.IO.FileAccess.Read); var xps = doc.GetFixedDocumentSequence(); DocumentViewer1.Document = xps; }
/// <summary> /// Convert an XPS document to a Bitmap image /// </summary> /// <param name="xpsFileName">The path of the XPS document</param> /// <param name="bitmapFileName">The path of the bitmap image to create</param> static public void ToBitmap(string xpsFileName, string bitmapFileName) { // Create a new instance of the Xps documr System.Windows.Xps.Packaging.XpsDocument xpsDoc = new System.Windows.Xps.Packaging.XpsDocument(xpsFileName, System.IO.FileAccess.Read); FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence(); // Interate throught the total number of pages. for (int pageNum = 0; pageNum < docSeq.DocumentPaginator.PageCount; ++pageNum) { // Get the current document page. DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum); // Create a new bitmap image. BitmapImage bitmap = new BitmapImage(); // Create a new bitmap render engine. RenderTargetBitmap renderTarget = new RenderTargetBitmap((int)docPage.Size.Width, (int)docPage.Size.Height, 96, // WPF (Avalon) units are 96dpi based 96, System.Windows.Media.PixelFormats.Default); // Render the current page to the image renderTarget.Render(docPage.Visual); // Encode the image as a bitmap BitmapEncoder encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(renderTarget)); // Save the image to the file using (FileStream pageOutStream = new FileStream(bitmapFileName, FileMode.Create, FileAccess.Write)) { // Save the image to the image file. encoder.Save(pageOutStream); pageOutStream.Close(); } } }