翻譯|使用教程|編輯:胡濤|2022-11-22 10:09:04.397|閱讀 180 次
概述:在本文中,我們將通過幾個(gè)簡(jiǎn)單的步驟向您展示如何在 C# 中將 XPS 轉(zhuǎn)換為 TIFF 。歡迎查閱
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Page是獨(dú)立的XPS和PostScript文件操作和轉(zhuǎn)換API。您是否正在尋找將文件轉(zhuǎn)換為格式的方法?如果是這樣,那么您來對(duì)地方了。在本文中,我們將通過幾個(gè)簡(jiǎn)單的步驟向您展示如何在 C# 中將 XPS 轉(zhuǎn)換為 TIFF 。
首先,我們將了解 XPS 到 TIFF 轉(zhuǎn)換器 API,以將 XPS 文件轉(zhuǎn)換為 TIFF 格式。接下來,我們將介紹如何進(jìn)行轉(zhuǎn)換的步驟。最后,我們將提供對(duì)免費(fèi)在線轉(zhuǎn)換工具和其他有用鏈接的訪問,以進(jìn)一步增強(qiáng)功能。讓我們開始吧!
為了將XPS 轉(zhuǎn)換為 TIFF,我們將使用Aspose.Page for .NET API。它使我們能夠在 C# 應(yīng)用程序中加載、合并、轉(zhuǎn)換和呈現(xiàn) XPS、和
API的類封裝了 XPS 文檔。API的類包含管理 TIFF 保存過程所需的選項(xiàng)。ImageDevice類封裝了文檔對(duì)圖像的渲染方法使用 Device 實(shí)例保存 XPS 文檔。
請(qǐng)安裝它。
PM> Install-Package Aspose.Page
我們可以按照以下步驟輕松地將 XPS 文件轉(zhuǎn)換為 TIFF 格式:
以下部分介紹如何將這些步驟轉(zhuǎn)換為 C# 代碼并將 XPS 文件轉(zhuǎn)換為 TIFF 格式。
我們可以按照以下步驟將 XPS 文件轉(zhuǎn)換為 TIFF 圖像:
以下代碼示例顯示如何使用 C# 將 XPS 文件轉(zhuǎn)換為 TIFF 圖像。
// This code example demonstrates how to convert XPS to TIFF. // The path to the documents directory. string dataDir = "C:\\Files\\"; // Input file string inputFileName = dataDir + "sample.xps"; // Outut file string outputFileName = "sample_out.tif"; // Initialize XPS input stream using (Stream xpsStream = File.Open(inputFileName, FileMode.Open, FileAccess.Read)) { // Load XPS document form the stream XpsDocument document = new XpsDocument(xpsStream, new XpsLoadOptions()); // or load XPS document directly from file. No xpsStream is needed then. // XpsDocument document = new XpsDocument(inputFileName, new XpsLoadOptions()); // Initialize options object with necessary parameters. TiffSaveOptions options = new TiffSaveOptions() { SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality, Resolution = 300, PageNumbers = new int[] { 1, 2, 6 } }; // Create rendering device for PDF format ImageDevice device = new ImageDevice(); document.Save(device, options); // Iterate through document partitions (fixed documents, in XPS terms) for (int i = 0; i < device.Result.Length; i++) { // Iterate through partition pages for (int j = 0; j < device.Result[i].Length; j++) { // Initialize image output stream using (Stream imageStream = System.IO.File.Open(dataDir + Path.GetFileNameWithoutExtension(outputFileName) + "_" + (i + 1) + "_" + (j + 1) + Path.GetExtension(outputFileName), System.IO.FileMode.Create, System.IO.FileAccess.Write)) // Write image imageStream.Write(device.Result[i][j], 0, device.Result[i][j].Length); } // End inner for } // End outer for } // End using
在本文中,我們學(xué)習(xí)了如何在 C# 中將 XPS 轉(zhuǎn)換為 TIFF。我們已經(jīng)看到這個(gè)過程比較簡(jiǎn)單,只需要幾行代碼。有了這些知識(shí),開發(fā)人員可以輕松地將 XPS 到 TIFF 的轉(zhuǎn)換功能添加到他們的應(yīng)用程序中。如有產(chǎn)品授權(quán)相關(guān)需求,您可以聯(lián)系我們。
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn