Essential Studio for Asp.Net | Demos

SHOWCASE SAMPLES
Showcase samples
    This sample demonstrates how to convert XPS to PDF document.

    Select Document



    More information about XPS to PDF document can be found in this documentation section.
    <%@ Page Language="C#" MasterPageFile="~/Samplebrowser.Master" AutoEventWireup="true" CodeBehind="XPStoPDF.aspx.cs" Inherits="WebSampleBrowser.Pdf.XPStoPDF" %>
    
    <asp:Content ID="Content3" ContentPlaceHolderID="ControlsSection" runat="server">
        <div style = "font-size: 17px;font-weight: 400;">
            This sample demonstrates how to convert XPS to PDF document.
    
        </div>
        
          <br />
                        <div>
                            <b>Select Document</b>
                            <asp:FileUpload ID="FileUpload1" Width="75%" runat="server" />
                        </div>
                        <br />
                       
                        <br />
                        <div style="border: solid 1px #788DB3; padding: 5px 7px 5px 7px; background-color: #EDF0F7;">
                            <table width="100%" cellpadding="0" cellspacing="0" border="0">
                                <tr>
                                    <td valign="middle" align="left">
                                        <asp:CheckBox runat="server" ID="CheckBox1" Text=" Open File inside the Browser"
                                            AutoPostBack="false" />
                                    </td>
                                    <td align="right">
                                        <asp:Button ID="btnXPStoPDF" Width="128px" Height="24px" runat="server" Text="Convert to PDF"
                                            OnClick="btnXPStoPDF_Click" />
                                    </td>
                                </tr>
                            </table>
                        </div>
                  
            <div>
                <asp:Label Width="100%" ForeColor="red" Style="text-align: justify;" ID="label1"
                    runat="server" Text=""></asp:Label>
            </div>
            <br />
             <div style = "font-size: 17px;font-weight: 400;">
    More information about XPS to PDF document can be found in this documentation <a href="https://help.syncfusion.com/file-formats/pdf/working-with-document-conversions#converting-xps-document-to-pdf">section.</a>
    
    
    
               </div>
            
        
    </asp:Content>
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.IO;
    
    using Syncfusion.Pdf;
    using Syncfusion.XPS;
    
    namespace WebSampleBrowser.Pdf
    {
        public partial class XPStoPDF : System.Web.UI.Page
        {
            protected void btnXPStoPDF_Click(object sender, EventArgs e)
            {
                if (this.FileUpload1.HasFile)
                {
                    string ext = System.IO.Path.GetExtension(this.FileUpload1.PostedFile.FileName).ToLower();
                    if (ext == ".xps")
                    {
                        //Convert the input XPS document to a PDF file
                        # region Convert XPS to PDF
                        Stream readFile = this.FileUpload1.PostedFile.InputStream;
                        try
                        {
                            XPSToPdfConverter converter = new XPSToPdfConverter();
                            //Convert XPS document into PDF document
                            PdfDocument document = converter.Convert(readFile);
    
                            //Save the pdf file            
                            if (this.CheckBox1.Checked)
                            {
                                document.Save("XPStoPDF.pdf", Response, HttpReadType.Open);
                            }
                            else
                            {
                                document.Save("XPStoPDF.pdf", Response, HttpReadType.Save);
                            }
    
                            readFile.Close();
                            this.label1.Text = "";
                            document.Close(true);
                        }
                        catch (Exception)
                        {
                            this.label1.Text = "The input document could not be processed, Could you please email the document to support@syncfusion.com for troubleshooting?";
                        }
                        # endregion
                    }
                    else
                    {
                        this.label1.Text = "Please choose a XPS file to convert to PDF";
                    }
    
                }
                else
                {
                    this.label1.Text = "Browse a XPS document and then click the button to convert as a PDF document";
                }
            }
        }
    }