How to convert xps file to bmp file

XPS, short for XML Paper Specification, is a markup format that serves as a representation of a page's content in the Windows Presentation Foundation (WPF) vector format. It provides a versatile and efficient means of encapsulating visual information for various purposes.

One key aspect of XPS is the XPS Document Writer, which empowers users to create .xps files using any program installed on their Windows operating system. This flexibility enables seamless integration with a wide range of applications, allowing users to generate XPS documents from diverse software tools.

The following VB.NET program convert and xps document to a bitmap image. Create a new VB.NET project and add a Button to Form and add the following references to your project.

Go to Project->Add References and select these files from .Net tab

  1. windowsbase.dll
  2. ReachFramework.dll
  3. PresentationFramework.dll
  4. PresentationCore.dll
Full Source VB.NET
Imports System Imports System.IO Imports System.IO.Packaging Imports System.Windows.Documents Imports System.Windows.Xps.Packaging Imports System.Windows.Media.Imaging Imports System.Collections.Generic Imports System.Windows.Forms Imports System.Text Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Try Dim xpsFile As String = "c:\Completed-Form.xps" xpsToBmp(xpsFile) MessageBox.Show("Done") Catch ex As Exception MessageBox.Show(ex.Message) End Try End Sub Public Shared Sub xpsToBmp(ByVal xpsFile As String) Dim xps As New XpsDocument(xpsFile, System.IO.FileAccess.Read) Dim sequence As FixedDocumentSequence = xps.GetFixedDocumentSequence() For pageCount As Integer = 0 To sequence.DocumentPaginator.PageCount - 1 Dim page As DocumentPage = sequence.DocumentPaginator.GetPage(pageCount) Dim toBitmap As New RenderTargetBitmap(CInt(page.Size.Width), CInt(page.Size.Height), 96, 96, System.Windows.Media.PixelFormats.[Default]) toBitmap.Render(page.Visual) Dim bmpEncoder As BitmapEncoder = New BmpBitmapEncoder() bmpEncoder.Frames.Add(BitmapFrame.Create(toBitmap)) Dim fStream As New FileStream("c:\xpstobmp" & pageCount & ".bmp", FileMode.Create, FileAccess.Write) bmpEncoder.Save(fStream) fStream.Close() Next End Sub End Class

A notable advantage of XPS documents is their consistent appearance across different platforms. Whether viewed on a screen or printed on paper, XPS documents retain their visual fidelity, ensuring that the content remains consistent in both digital and physical formats. This feature is particularly valuable for tasks such as document sharing and collaboration.

The versatility of XPS documents further extends to their portability. Since XPS viewers can be installed on any computer, users can easily share XPS documents with others, regardless of whether the recipient has the same programs used to create the original files. This accessibility promotes seamless document sharing and ensures that the intended visual representation is preserved across various computing environments.

Conclusion

XPS is an XML markup format that represents page content in the Windows Presentation Foundation vector format. The XPS Document Writer enables the creation of XPS files from any program running on Windows, ensuring consistent appearance and ease of sharing. Furthermore, a VB.NET program can be developed to convert XPS documents to bitmap images, providing additional flexibility and utilization options for XPS content.