打开 XPS
读取 XPS 文件 Viewer API 解决方案 for .NET。
Aspose.Page 提供 XPS 查看器功能,可以使用 .NET 平台支持的任何语言读取和呈现 XPS 文件:C#、VB、J#。
您在此处看到的 API 可用于创建您自己的跨平台应用程序或集成到您的 .NET 项目中。
要打开 XPS 文件,请使用:
Aspose.Page for .NET API 是一个功能丰富、功能强大且易于使用的 C# 平台文档操作和转换 API。
打开 NuGet 包管理器,搜索 Aspose.Page 并安装。您也可以从包管理器控制台使用以下命令。
Package Manager Console Command
PM> Install-Package Aspose.Page
通过 C# 查看的步骤
Aspose.Page 使开发人员只需几行代码即可轻松查看 XPS 文件。
- 使用 PsDocument 类的实例加载 XPS 文件。
- 创建和设置 PdfSaveOptions 和 PdfDevice 类的实例。
- 使用 PdfSaveOptions 和 PdfDevice 对象作为参数调用 PsDocument.Save 方法。
- 使用生成的 PDF 的路径调用 Process.Start 以将其加载到默认应用程序中。
系统要求
所有主要操作系统都支持 Aspose.Page for .NET。只需确保您具有以下先决条件:
- Microsoft Windows 或具有 .NET Framework 平台、Windows 和 ASP.NET 应用程序的兼容操作系统。
- Microsoft Visual Studio 等开发环境。
- 项目中引用的 .NET DLL 的 Aspose.Page。
C#代码查看XPS
string output = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString() + ".pdf";
// create a stream for input XPS file
using (var psStream = new System.IO.FileStream("template.xps", System.IO.FileMode.Create, System.IO.FileAccess.Read))
{
// create a stream for output PDF file
using (var pdfStream = System.IO.File.Open(output, System.IO.FileMode.Open, System.IO.FileAccess.Write))
{
// load the XPS file from stream
var document = new Aspose.Page.XPS.PsDocument(psStream);
// create an instance of PdfSaveOptions
var options = new Aspose.Page.XPS.Device.PdfSaveOptions();
// create PDF rendering device for XPS
var device = new Aspose.Page.XPS.Device.PdfDevice(pdfStream);
// save XPS as PDF
ocument.Save(device, options);
}
}
// load resultant PDF in default application
System.Diagnostics.Process.Start(output);XPS 什么是XPS文件格式
XPS(XML Paper Specification)是 Microsoft 的 PDF 替代方案,基于 XML/HTML,跨平台保持布局一致,且不依赖操作系统。