How to convert xps file to bmp file

XPS is an xml markup format that represents a page's content in Windows Presentation Foundation vector format. The XPS Document Writer allows you to create .xps files using any program that you run on Windows. XPS documents look the same in print as they do on the screen. They are also easy to share because you can view them on any computer where an XPS viewer is installed, even if the computer does not have the same programs that you used to create the original documents.

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

  windowsbase.dll
  ReachFramework.dll
  PresentationFramework.dll

PresentationCore.dll




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

 VB.NET Files - Related Contents


 VB.NET Files - Related Programs

.