I have a simple C # .net web application. In this I work with XPS files. I 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 appears showing XamlParserException
'An exception was made when calling a constructor of the type' System.Windows.Documents.DocumentReference 'that matches the specified binding constraints.' Line number "2" and line position "20".
in the following line of code:
FixedDocumentSequence sequence = xps.GetFixedDocumentSequence();
I downloaded a sample XPS file from http://msdn.microsoft.com/en-us/library/windows/hardware/gg463422.aspx (I got a 160 megabyte zip file from there. When I unzip it, the number of folders and files with the extension .xps. I do not know how to use these files) and is used in the above code. I am very new to this file concept. I do not know how to solve this error and how .xps files are used. I also have little information about bitmap files.
source share