SiteMap  | About    

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


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
            Dim xpsFile As String = "c:\Completed-Form.xps"
        Catch ex As Exception
        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])


            Dim bmpEncoder As BitmapEncoder = New BmpBitmapEncoder()

            Dim fStream As New FileStream("c:\xpstobmp" & pageCount & ".bmp", FileMode.Create, FileAccess.Write)
    End Sub
End Class (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.