翻譯|使用教程|編輯:胡濤|2022-11-22 10:09:04.397|閱讀 180 次
概述:在本文中,我們將通過幾個簡單的步驟向您展示如何在 C# 中將 XPS 轉換為 TIFF 。歡迎查閱
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
Aspose.Page是獨立的XPS和PostScript文件操作和轉換API。您是否正在尋找將文件轉換為格式的方法?如果是這樣,那么您來對地方了。在本文中,我們將通過幾個簡單的步驟向您展示如何在 C# 中將 XPS 轉換為 TIFF 。
首先,我們將了解 XPS 到 TIFF 轉換器 API,以將 XPS 文件轉換為 TIFF 格式。接下來,我們將介紹如何進行轉換的步驟。最后,我們將提供對免費在線轉換工具和其他有用鏈接的訪問,以進一步增強功能。讓我們開始吧!
為了將XPS 轉換為 TIFF,我們將使用Aspose.Page for .NET API。它使我們能夠在 C# 應用程序中加載、合并、轉換和呈現 XPS、和
API的類封裝了 XPS 文檔。API的類包含管理 TIFF 保存過程所需的選項。ImageDevice類封裝了文檔對圖像的渲染方法使用 Device 實例保存 XPS 文檔。
請安裝它。
PM> Install-Package Aspose.Page
我們可以按照以下步驟輕松地將 XPS 文件轉換為 TIFF 格式:
以下部分介紹如何將這些步驟轉換為 C# 代碼并將 XPS 文件轉換為 TIFF 格式。
我們可以按照以下步驟將 XPS 文件轉換為 TIFF 圖像:
以下代碼示例顯示如何使用 C# 將 XPS 文件轉換為 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
在本文中,我們學習了如何在 C# 中將 XPS 轉換為 TIFF。我們已經看到這個過程比較簡單,只需要幾行代碼。有了這些知識,開發人員可以輕松地將 XPS 到 TIFF 的轉換功能添加到他們的應用程序中。如有產品授權相關需求,您可以聯系我們。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn