翻譯|行業資訊|編輯:胡濤|2024-07-24 10:11:36.210|閱讀 94 次
概述:本指南適用于正在尋找PostScript Java庫以編程方式將 PostScript 轉換為GIF 的Java 程序員。您幾乎可以在所有流行的操作系統上輕松打開 GIF 圖像,而無需安裝軟件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
現在將PostScript文件轉換為高質量圖像并不是一件難事。Aspose.Page為多種編程語言提供高代碼 API,以便以編程方式轉換和操作 PS 文件。此外,它還支持企業級在線PS文件轉換器,以將 PS 文件轉換為其他流行的文件格式。但是,本指南適用于正在尋找PostScript Java庫以編程方式將 PostScript 轉換為GIF 的Java 程序員。您幾乎可以在所有流行的操作系統上輕松打開 GIF 圖像,而無需安裝軟件。那么,讓我們開始吧。
Aspose.Page for Java - 用于XPS,PS和EPS的Java文件操作API,允許用戶創建,解析和保存XPS文件,以及在文檔中添加和刪除頁面。允許將PS和EPS文件轉換為PDF和光柵圖像格式。允許開發人員為XPS文檔創建畫布,路徑和字形元素,并執行諸如添加或刪除頁面,創建矢量和字符串,使用畫筆以及操縱元素外觀等操
為了安裝Aspose.Page for Java,您可以 下載JAR 文件或使用以下 Maven 配置:
<repositories> <repository> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>//releases.aspose.com/java/repo/</url> </repository> </repositories> <dependencies> <dependency> <groupId>com.aspose</groupId> <artifactId>aspose-page</artifactId> <version>23.12</version> </dependency> </dependencies>
此外,您可以訪問此指南來了解完整的詳細信息。
	 
 
現在,您可以開發一款 PS 轉 GIF 制作器,用于商業軟件。因此,請按照以下步驟操作:
以下代碼示例演示了如何以編程方式在 Java 中將 PostScript 轉換為 GIF:
package com.example;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import com.aspose.eps.PsDocument;
import com.aspose.eps.device.ImageDevice;
import com.aspose.eps.device.ImageSaveOptions;
public class Main {
// High Code Java API to Convert PostScript to GIF
public static void main(String[] args) throws Exception {
// Set the ImageFormat to GIF.
com.aspose.page.ImageFormat imageFormat = com.aspose.page.ImageFormat.GIF;
// Load the source PostScript file.
FileInputStream psStream = new FileInputStream("/input.ps");
// Initialize an object of the PsDocument class with the PostScript input stream.
PsDocument document = new PsDocument(psStream);
// Set the value of suppressErrors if you want to convert the Postscript file despite minor errors.
boolean suppressErrors = true;
// Instantiate a new object of ImageSaveOptions class with suppressErrors parameter.
ImageSaveOptions options = new ImageSaveOptions(suppressErrors);
// Create an instance of the ImageDevice class.
ImageDevice device = new ImageDevice();
try {
// Call the save method to save the GIF file on the disk.
document.save(device, options);
} finally {
psStream.close();
}
// Invoke the getImagesBytes method to get the resulting images in bytes.
byte[][] imagesBytes = device.getImagesBytes();
int i = 0;
for (byte [] imageBytes : imagesBytes) {
String imagePath = "/PSToGIF" + i + "." + imageFormat.toString().toLowerCase();
// Create output stream by initializing an instance of the FileOutputStream class with the output image path.
FileOutputStream fs = new FileOutputStream(imagePath);
try {
fs.write(imageBytes, 0, imageBytes.length);
} catch (IOException ex) {
System.out.println(ex.getMessage());
} finally {
fs.close();
}
i++;
}
//Review errors
if (suppressErrors) {
for (Exception ex : options.getExceptions()) {
System.out.println(ex.getMessage());
}
}
}
}
您可以在下圖中看到輸出:
	 
 
此提供支持,是一款免費工具。此外,它在轉換為其他文件格式時保持文本和圖形數據的質量。我們強烈建議您使用此PS 文件轉換器來提高工作效率。
	 
 
綜上所述,我們已經了解了如何以編程方式在 Java 中將 PostScript 轉換為 GIF。此外,我們還實現了開發高效PS 文件轉換器的功能。同樣,您可以通過訪問文檔、GitHub repo和 API參考來進一步探索此 PostScript Java 庫。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@ke049m.cn