编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

XPS转PDF不再愁!全新XPS/EPS文档处理神器Aspose.Page来啦

wxchong 2024-07-15 10:08:53 开源技术 36 ℃ 0 评论

近月,针对Aspose.XPS和Aspose.EPS做了一些改动,将其合并成Aspose.Page,同样可以使用现有许可证访问这两种产品的所有功能。

Aspose.Page是集成On-Premise API,以.NET和Java应用程序中创建,操作或转换XPS,EPS和PS文件。或使用免费应用程序即时查看或转换文件。

功能亮点

Aspose.Page允许文档转换。例如,您可以将XPS转换为PDF。让我们试试转换的例子。

.NET

//文档目录的路径。
string dataDir = RunExamples.GetDataDir_WorkingWithDocumentConversion();
//初始化PDF输出流
using (System.IO.Stream pdfStream = System.IO.File.Open(dataDir + "input.xps", System.IO.FileMode.Create, System.IO.FileAccess.Write))
//初始化XPS输入流
using (System.IO.Stream xpsStream = System.IO.File.Open(dataDir + "XPStoPDF.pdf", System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
 //从流中加载XPS文档
 XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions());
 //或直接从文件加载XPS文档。那么不需要xpsStream。
 // XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions());
 //使用必要参数初始化选项对象。
 Aspose.Page.Xps.Presentation.Pdf.PdfSaveOptions options = new Aspose.Page.Xps.Presentation.Pdf.PdfSaveOptions()
 {
 JpegQualityLevel = 100,
 ImageCompression = Aspose.Page.Xps.Presentation.Pdf.PdfImageCompression.Jpeg,
 TextCompression = Aspose.Page.Xps.Presentation.Pdf.PdfTextCompression.Flate,
 PageNumbers = new int[] { 1, 2, 6 }
 };
 //为PDF格式创建渲染设备
 Aspose.Page.Xps.Presentation.Pdf.PdfDevice device = new Aspose.Page.Xps.Presentation.Pdf.PdfDevice(pdfStream);
 document.Save(device, options);
}

Java

// 文档目录的路径。
String dataDir = Utils.getDataDir();
//初始化PDF输出流
FileOutputStream pdfStream = new FileOutputStream(dataDir + "XPStoPDF.pdf");
//加载XPS文档
XpsDocument document = new XpsDocument(dataDir + "input.xps");
//使用必要参数初始化选项对象。
com.aspose.xps.rendering.PdfSaveOptions options = new com.aspose.xps.rendering.PdfSaveOptions();
options.setJpegQualityLevel(100);
options.setImageCompression(com.aspose.xps.rendering.PdfImageCompression.Jpeg);
options.setTextCompression(com.aspose.xps.rendering.PdfTextCompression.Flate);
options.setPageNumbers(new int[] { 1, 2, 6 });
//为PDF格式创建渲染设备
com.aspose.xps.rendering.PdfDevice device = new com.aspose.xps.rendering.PdfDevice(pdfStream);
document.save(device, options);

点击下方“了解更多”免费下载Aspose.Page最新版

↓↓↓

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表