PS 및 EPS 변환

PS 및 EPS 변환

PsDocument은(는) PostScript (.ps) 및 캡슐화된 PostScript (.eps) 파일을 로드하기 위한 진입점입니다. 두 형식 모두 동일한 클래스와 동일한 인터페이스를 통해 처리됩니다.


PS 또는 EPS 파일 로드

PsDocument.from_file()을(를) 사용하여 파일 경로에서 문서를 로드합니다. is_eps 속성은 로드된 파일이 EPS 파일인지 여부를 나타냅니다.

from aspose.page.ps.document import PsDocument

ps = PsDocument.from_file("document.ps")
eps = PsDocument.from_file("illustration.eps")
print("Is EPS:", eps.is_eps)

원시 바이트(예: 업로드 또는 네트워크 스트림)에서 로드하려면 from_bytes()을(를) 사용하세요:

from aspose.page.ps.document import PsDocument

with open("document.ps", "rb") as f:
    data = f.read()
doc = PsDocument.from_bytes(data)

PDF로 내보내기

로드된 PsDocument에 대해 to_pdf()을 호출하여 PDF 바이트 배열을 얻습니다. 결과를 디스크에 기록하거나 HTTP 핸들러에서 직접 반환하십시오.

from pathlib import Path
from aspose.page.ps.document import PsDocument

ps = PsDocument.from_file("input.ps")
pdf_bytes = ps.to_pdf()
Path("output.pdf").write_bytes(pdf_bytes)

PNG 또는 JPEG로 내보내기

ImageSaveOptions 인스턴스를 to_image()에 전달합니다. format를 "png" 또는 "jpeg"로 설정하고 dpi를 원하는 해상도로 설정합니다.

from pathlib import Path
from aspose.page.ps.document import PsDocument
from aspose.page.ps.output import ImageSaveOptions

eps = PsDocument.from_file("illustration.eps")
opts = ImageSaveOptions(format="png", dpi=150)
Path("output.png").write_bytes(eps.to_image(opts))

EPS DSC 메타데이터 읽기

PsDocument.dsc은(는) EPS 파일에 DSC 헤더 주석이 있을 때 DscMetadata 인스턴스를 반환합니다. 변환하기 전에 경계 상자, 제목 및 작성자 필드를 읽는 데 사용하십시오.

from aspose.page.ps.document import PsDocument

eps = PsDocument.from_file("illustration.eps")
dsc = eps.dsc
if dsc is not None:
    print("Title:", dsc.title)
    print("Bounding box:", dsc.bounding_box)
    print("Creator:", dsc.creator)

팁 및 모범 사례

  • 임시 파일 작성을 방지하기 위해 업로드를 처리할 때 from_bytes()을(를) 사용하십시오.
  • PS와 EPS 파일이 혼합된 배치를 처리할 때 로직을 분기하려면 is_eps을(를) 확인하십시오.
  • 문서 미리보기 시스템에서 사용되는 래스터 출력에 대해 dpi=150 이상으로 설정하십시오.
  • 모든 변환 메서드는 bytes을 반환합니다 — 필요에 따라 디스크 I/O 없이 저장하거나 스트리밍하세요.

일반적인 문제

문제원인수정
FileNotFoundErrorfrom_file()에 전달된 경로가 존재하지 않습니다from_file()를 호출하기 전에 파일 경로를 확인하십시오
PDF 출력이 비어 있습니다PS 파일에 렌더링 가능한 내용이 없습니다PS 소스에서 누락된 showpage 연산자를 검사합니다
저해상도 래스터기본 DPI는 96입니다ImageSaveOptions(dpi=150) 이상을 통과

FAQ

EPS 파일을 PDF로 변환할 수 있나요?

예. PsDocument.from_file()은(는) .ps와 .eps 확장자를 모두 지원합니다. 반환된 문서에서 to_pdf()을 호출하면 PDF 바이트를 얻을 수 있습니다.

변환에 Ghostscript가 필요합니까?

아니요. 이 라이브러리는 Ghostscript나 어떤 네이티브 런타임에도 의존하지 않습니다.

디스크에 쓰지 않고 PS 파일을 처리할 수 있나요?

네. from_bytes()을(를) 사용하여 bytes 객체에서 로드하고, to_pdf() 또는 to_image()에서 반환된 bytes를 직접 사용하십시오 — 파일을 작성할 필요가 없습니다.


API Reference 요약

클래스 / 메서드설명
PsDocument.from_file(path)파일 경로에서 PS 또는 EPS를 로드합니다
PsDocument.from_bytes(data)원시 바이트에서 PS 또는 EPS를 로드
PsDocument.to_pdf(options)PDF 바이트로 내보내기
PsDocument.to_image(options)래스터 이미지 바이트로 내보내기
PsDocument.is_eps로드된 파일이 EPS인 경우 True
PsDocument.dscDSC 헤더 메타데이터 (EPS 파일)
DscMetadata.bounding_boxEPS 경계 상자를 (x0, y0, x1, y1) 형태로
DscMetadata.titleEPS DSC 헤더의 제목
ImageSaveOptions.format출력 형식: “png” 또는 “jpeg”
ImageSaveOptions.dpiDPI 단위 출력 해상도

참조

 한국어