我有一个简单的C#.NET Web应用程序。 在我与XPS文件的工作。 我用下面的代码
private void button1_Click(object sender, EventArgs e)
{
try
{
string xpsFile = "D:\\Completed-Form.xps";
xpsToBmp(xpsFile);
MessageBox.Show("Done");
}
catch (Exception ex)
{
MessageBox.Show (ex.Message);
}
}
static public void xpsToBmp(string xpsFile)
{
XpsDocument xps = new XpsDocument(xpsFile, System.IO.FileAccess.Read);
FixedDocumentSequence sequence = xps.GetFixedDocumentSequence();
for (int pageCount = 0; pageCount < sequence.DocumentPaginator.PageCount; ++pageCount)
{
DocumentPage page = sequence.DocumentPaginator.GetPage(pageCount);
RenderTargetBitmap toBitmap = new RenderTargetBitmap((int)page.Size.Width,(int)page.Size.Height,96,96,System.Windows.Media.PixelFormats.Default);
toBitmap.Render(page.Visual);
BitmapEncoder bmpEncoder = new BmpBitmapEncoder();
bmpEncoder.Frames.Add(BitmapFrame.Create(toBitmap));
FileStream fStream = new FileStream("D:\\xpstobmp" + pageCount + ".bmp", FileMode.Create, FileAccess.Write);
bmpEncoder.Save(fStream);
fStream.Close();
}
}
当我调试的代码,表示作为一个错误XamlParserException
发生
System.Windows.Documents.DocumentReference“上类型构造函数的调用‘’匹配指定绑定约束引发了异常。” 行号“2”和线位置“20”。
在下面的代码行:
FixedDocumentSequence sequence = xps.GetFixedDocumentSequence();
我已经下载了从样品XPS文件http://msdn.microsoft.com/en-us/library/windows/hardware/gg463422.aspx (我从那里得到160MB的zip文件。当我把它解压有一些文件夹并且具有文件.XPS扩展。我不知道如何使用这些文件),并在上面的代码中使用。 我非常新的这个文件的概念。 我不知道如何解决这个错误和.XPS文件是如何使用的。 我也有关于位图文件知之甚少。