合併合併 PS C#

PS 文件將數字頁面佈局轉換為展示文本和圖形正確組合的印刷副本。在某些情況下,您可能需要將不同的 PostScript PS 文件合併為一個文件。根據此類要求,本文介紹瞭如何在 C# 中以編程方式合併或組合 PS 文件。

組合或合併 PS 文件 – C# API 安裝

Aspose.Page for .NET API 設計用於處理頁面描述語言格式,如 PS、EPS、XPS。只需從 New Releases 部分下載其 DLL 文件或使用以下 NuGet 安裝命令即可訪問 API:

PM> Install-Package Aspose.Page

在 C# 中以編程方式合併 PS 文件

您需要按照以下步驟將不同的 PS 文件合併為一個文件:

  1. 加載源 PostScript PS 文檔以附加其他文件。
  2. 創建一個 PdfSaveOptions 類實例。
  3. 獲取要合併的源文件。
  4. 合併 PostScript PS 文件。

以下示例代碼顯示瞭如何在 C# 中以編程方式合併 PS 文件:

// 初始化 PDF 輸出流
System.IO.FileStream pdfStream = new System.IO.FileStream("outputPDF_out.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write);

// 初始化第一個 PostScript 文件輸入流
System.IO.FileStream psStream = new System.IO.FileStream("input.ps", System.IO.FileMode.Open, System.IO.FileAccess.Read);

Aspose.Page.EPS.PsDocument document = new Aspose.Page.EPS.PsDocument(psStream);

// 創建一組將與第一個文件合併的 PostScript 文件
String[] filesForMerge = new String[] { "input2.ps", "input3.ps" };

// 使用必要的參數初始化選項對象。
Aspose.Page.EPS.Device.PdfSaveOptions options = new Aspose.Page.EPS.Device.PdfSaveOptions(true);

// 初始化 PdfDevice 類對象
Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream);

try
{
    document.Merge(filesForMerge, device, options);
}
finally
{
    psStream.Close();
    pdfStream.Close();
}

在 C# 中使用高級屬性合併 PS 文件

Aspose.Page for .NET API 公開了許多高級屬性以增強 PS 合併過程。請按照以下步驟設置輸出文檔的不同屬性:

  1. 加載用於合併 PostScript 文件的輸入 PS 文件。
  2. 指定 PdfSaveOptions 類的屬性。
  3. 將 PostScript 文件合併為一個文件。

以下代碼片段演示瞭如何在 C# 中使用高級選項合併 PS 文件:

// 初始化 PDF 輸出流
System.IO.FileStream pdfStream = new System.IO.FileStream("outputPDF_out.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write);

// 初始化第一個 PostScript 文件輸入流
System.IO.FileStream psStream = new System.IO.FileStream("input.ps", System.IO.FileMode.Open, System.IO.FileAccess.Read);

Aspose.Page.EPS.PsDocument document = new Aspose.Page.EPS.PsDocument(psStream);

// 創建一組將與第一個文件合併的 PostScript 文件
String[] filesForMerge = new String[] { "input2.ps", "input3.ps" };

// 使用必要的參數初始化選項對象。
Aspose.Page.EPS.Device.PdfSaveOptions options = new Aspose.Page.EPS.Device.PdfSaveOptions(true);
options.JpegQualityLevel = 100;
options.SupressErrors = true;
options.Debug = false;


// // 使用以下行初始化 PdfDevice 類對象
Aspose.Page.EPS.Device.PdfDevice device = new Aspose.Page.EPS.Device.PdfDevice(pdfStream, new System.Drawing.Size(595, 842));
try
{
    document.Merge(filesForMerge, device, options);
}
finally
{
    psStream.Close();
    pdfStream.Close();
}

獲得免費的臨時許可證

您可以通過申請 免費臨時許可證 來不受任何限制地評估 API。

結論

在本文中,您了解瞭如何在 C# 中以編程方式合併 PostScript PS 文件。它涵蓋了基本用例以及滿足您要求的高級功能。此外,您可以通過訪問 文檔 空間來探索 API 的其他功能。如果您有任何疑問或疑慮,請在 論壇 上寫信給我們。

也可以看看

在 C# 中將 XPS 或 OXPS 轉換為 Word DOCX/DOC