PS에서 JPEG로

C++용 API 솔루션을 통해 PS를 JPEG로 변환합니다.

 

PostScript(PS)는 강력하지만 직접 작업하기에는 복잡할 수 있는 페이지 설명 언어입니다. PS 파일은 다른 형식에 비해 직접 편집이 보편적으로 지원되지 않습니다. Adobe Acrobat이나 Ghostscript와 같은 애플리케이션은 PS 파일을 열고 해석할 수 있지만, 최신 형식에 비해 직접 편집이 덜 간소화되는 경우가 많습니다. 많은 사용자에게 PS 파일을 관리하기 쉬운 형식으로 변환하는 것이 바람직합니다. 이 API는 강력한 변환 기능을 제공하여 이러한 요구를 충족합니다.

C++ 개발자는 Aspose.Page를 활용하여 PostScript 파일을 JPEG와 같은 다양한 형식으로 효율적으로 변환할 수 있습니다. 이 API는 C++ 애플리케이션 내에서 PS 변환을 처리하기 위한 강력하고 쉽게 통합되는 솔루션을 제공합니다.

PS를 JPEG로 변환하려면:

  • Aspose.Page for C++ API는 기능이 풍부하고 강력하며 사용하기 쉬운 C++ 플랫폼용 문서 조작 및 변환 API입니다.

  • 최신 버전을 직접 다운로드하고 NuGet 패키지 관리자를 열고 Aspose.Page.Cpp를 검색하여 설치할 수 있습니다. 패키지 관리자 콘솔에서 다음 명령을 사용할 수도 있습니다.

Package Manager Console Command


    PM> Install-Package Aspose.Page.Cpp

C++를 사용하여 PS를 JPEG로 변환하는 단계

Aspose.Page를 사용하면 개발자가 단 몇 줄의 코드만으로 PS 파일을 쉽게 로드하고 JPEG로 변환할 수 있습니다.

  1. C++용 Aspose.Page를 사용하여 PS 파일을 로드합니다.
  2. ImageSaveOptions 클래스 의 객체를 생성하고 이미지 형식을 ImageFormat::Jpeg .
  3. 정의된 옵션을 사용하여 SaveAsImage 를 호출하는 이미지의 바이트 배열을 가져옵니다.
  4. 출력 스트림에 이미지 바이트를 기록하여 이미지를 저장합니다.
이 코드 샘플은 PS를 JPEG C++로 변환하는 방법을 설명합니다.
// The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
    
    // Initialize PsDocument with the name of PostScript file.
    System::SharedPtr<PsDocument> document = System::MakeObject<PsDocument>(dataDir + u"input.ps");
    
    // If you want to convert Postscript file despite of minor errors set this flag
    bool suppressErrors = true;
    
    //Initialize options object with necessary parameters.
    System::SharedPtr<ImageSaveOptions> options = System::MakeObject<ImageSaveOptions>();
    
    //Set output image format.
    options->set_ImageFormat(Aspose::Page::Drawing::Imaging::ImageFormat::Jpeg);
    
    // If you want to add special folder where fonts are stored. Default fonts folder in OS is always included.
    options->set_AdditionalFontsFolders(System::MakeArray<System::String>({u"{FONT_FOLDER}"}));
    
    // Save PS document as array of image bytes, one bytes array for one page.
    System::ArrayPtr<System::ArrayPtr<uint8_t>> imagesBytes = document->SaveAsImage(options);
    
    //Save images bytes arrays as image files.
    
    int32_t i = 0;
    
    for (System::ArrayPtr<uint8_t> imageBytes : imagesBytes)
    {
        System::String imagePath = System::IO::Path::GetFullPath(dataDir + u"out_image" + System::Convert::ToString(i) + u"." + System::ObjectExt::ToString(options->get_ImageFormat()).ToLower());
        {
            System::SharedPtr<System::IO::FileStream> fs = System::MakeObject<System::IO::FileStream>(imagePath, System::IO::FileMode::Create, System::IO::FileAccess::Write);
            // Clearing resources under 'using' statement
            System::Details::DisposeGuard<1> __dispose_guard_0({ fs});
            // ------------------------------------------
            
            try
            {
                fs->Write(imageBytes, 0, imageBytes->get_Length());
            }
            catch(...)
            {
                __dispose_guard_0.SetCurrentException(std::current_exception());
            }
        }
        i++;
    }
    
    
    //Review errors
    if (suppressErrors)
    {
        for (auto&& ex : System::IterateOver(options->get_Exceptions()))
        {
            System::Console::WriteLine(ex->get_Message());
        }
    }

PS What is PS File Format

PS (PostScript) は、テキストとグラフィックを 1 ファイルに統合するページ記述言語です。多くの画像編集・印刷ソフトでサポートされ、プリンタ向けの描画指示を含みます。

JPEG What is JPEG File Format

JPEG は、写真向けの有損圧縮形式で、画質とファイルサイズのバランスが取れています。高圧縮時に画質が低下します。