Java에서 PostScript를 GIF로 변환하기

PostScript 파일을 고품질 이미지로 변환하는 것은 이제 더 이상 어려운 일이 아닙니다. Aspose.Page는 여러 프로그래밍 언어를 위한 고급 코드 API를 제공하여 PS 파일을 프로그래밍 방식으로 변환하고 조작할 수 있습니다. 또한, PS 파일을 다른 인기 있는 파일 형식으로 변환할 수 있는 엔터프라이즈급 온라인 PS 파일 변환기도 지원합니다. 그러나 이 가이드는 PostScript를 GIF로 프로그래밍 방식으로 변환하려는 Java 프로그래머를 위한 것입니다. 거의 모든 인기 있는 운영 체제에서 소프트웨어를 설치하지 않고도 GIF 이미지를 쉽게 열 수 있습니다. 그럼 시작해 봅시다.

이 블로그 포스트에서는 다음 섹션을 다룰 것입니다:

  1. PostScript Java 라이브러리 설치
  2. Java에서 PostScript를 GIF로 변환하기 - 코드 샘플
  3. PS 파일 변환기 - 온라인 도구

PostScript Java 라이브러리 설치

Aspose.Page for Java를 설치하려면 JAR 파일을 다운로드하거나 다음 Maven 구성을 사용할 수 있습니다:

 <repositories>
     <repository>
         <id>AsposeJavaAPI</id>
         <name>Aspose Java API</name>
         <url>https://releases.aspose.com/java/repo/</url>
     </repository>
</repositories>
 <dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-page</artifactId>
        <version>23.12</version>
    </dependency>
</dependencies>

또한, 전체 세부정보를 확인하려면 이 설치 가이드를 방문할 수 있습니다.

PostScript Java 라이브러리

Java에서 PostScript를 GIF로 변환하기 - 코드 샘플

이제 비즈니스 소프트웨어를 위한 PS에서 GIF 제작기를 개발할 수 있습니다. 아래에 언급된 단계를 따르세요:

  • ImageFormat을 GIF로 설정하고 원본 PostScript 파일을 로드합니다.
  • PostScript 입력 스트림으로 PsDocument 클래스의 객체를 초기화합니다.
  • 경미한 오류에도 불구하고 Postscript 파일을 변환하려면 suppressErrors의 값을 설정합니다.
  • suppressErrors 매개변수로 ImageSaveOptions 클래스의 새 객체를 생성합니다.
  • ImageDevice 클래스의 인스턴스를 생성합니다.
  • save 메서드를 호출하여 GIF 파일을 디스크에 저장합니다.
  • getImagesBytes 메서드를 호출하여 결과 이미지를 바이트 단위로 가져옵니다.
  • 출력 이미지 경로로 FileOutputStream 클래스의 인스턴스를 초기화하여 출력 스트림을 생성합니다.

다음 코드 샘플은 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());
}
}
}
}

아래 이미지에서 출력을 확인할 수 있습니다:

이미지에서 GIF 제작기

PS 파일 변환기 - 온라인 도구

온라인 도구는 다른 널리 사용되는 파일 형식으로 PS 변환을 제공합니다. Aspose.Page에 의해 지원되며 무료 도구입니다. 또한, 다른 파일 형식으로 변환하는 동안 텍스트 및 그래픽 데이터의 품질을 유지합니다. 생산성을 높이기 위해 이 PS 파일 변환기를 사용하는 것을 강력히 권장합니다.

PS 파일 변환기

이미지에서 GIF 제작기 - 무료 라이센스 받기

이제 평가 한계를 넘어 PostScript Java 라이브러리를 사용해 볼 수 있는 무료 임시 라이센스를 이용할 수 있습니다.

결론

결론적으로, Java에서 PostScript를 GIF로 프로그래밍 방식으로 변환하는 방법을 살펴보았습니다. 또한, 효율적인 PS 파일 변환기를 개발하는 기능을 구현했습니다. 마찬가지로, 문서, GitHub 레포, 그리고 API 참조를 방문하여 이 PostScript Java 라이브러리를 더 탐색할 수 있습니다. 마지막으로, aspose.com은 블로그 포스트를 계속 발행할 것입니다. 따라서 업데이트를 위해 계속 지켜봐 주세요. 질문이나 문의사항은 포럼에 공유할 수 있습니다.

참고 사항