3

I'm trying to create xps file out of DocumentViewer:

Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
dlg.FileName = "MyReport"; // Default file name
dlg.DefaultExt = ".xps"; // Default file extension
dlg.Filter = "XPS Documents (.xps)|*.xps"; // Filter files by extension

// Show save file dialog box
Nullable<bool> result = dlg.ShowDialog();

// Process save file dialog box results
if (result == true)
{
    // Save document
    string filename = dlg.FileName;

    FixedDocument doc = (FixedDocument)documentViewer.Document;
    XpsDocument xpsd = new XpsDocument(filename, FileAccess.ReadWrite);
    System.Windows.Xps.XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
    xw.Write(doc);
    xpsd.Close();
}

BUT it throws the following exception in the xw.Write(doc):

BitmapMetadata is not available on BitmapImage

Either way, it creates a XPS file but in it i don't see anything (of course) but the following message:

This page cannot be displayed

1) I don't understand where this bitmap came from...

2) What can i do about this exception?

Thanks.

Noam M
  • 3,156
  • 5
  • 26
  • 41
israel altar
  • 1,768
  • 1
  • 16
  • 24

0 Answers0