I have a simple C# .net web application. In that I'm working with XPS files. I have used the following code
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();
}
}
When I debug the code, an error showing as XamlParserException
occurred
'The invocation of the constructor on type 'System.Windows.Documents.DocumentReference' that matches the specified binding constraints threw an exception.' Line number '2' and line position '20'.
in the following line of code:
FixedDocumentSequence sequence = xps.GetFixedDocumentSequence();
I have downloaded a sample XPS file from http://msdn.microsoft.com/en-us/library/windows/hardware/gg463422.aspx (I got 160MB zip file from there. When I unzip it there were a number of folders and files having .xps extension. I don't know how to use these files) and used in the above code. I'm very new to this file concept. I don't know how to resolve this error and how the .xps files are used. Also I have little knowledge about bitmap files.