PS to JPEG

Convert PS to JPEG via API Solution for C++.

 

PostScript (PS) is a page description language that, while powerful, can be complex to work with directly. PS files are less universally supported for direct editing than some other formats. While applications like Adobe Acrobat and Ghostscript can open and interpret PS files, direct editing is often less streamlined compared to more modern formats. For many users, converting PS files to a more manageable format is desirable. This API addresses that need by providing robust conversion capabilities.

C++ developers can leverage Aspose.Page to efficiently convert PostScript files to a wide range of formats like JPEG. The API provides a robust and easily integrated solution for handling PS conversion within C++ applications.

In order to convert PS to JPEG:

  • Aspose.Page for C++ API, which is a feature-rich, powerful, and easy-to-use document manipulation and conversion API for C++ platform.

  • You can download its latest version directly, just open NuGet package manager, and search for Aspose.Page.Cpp and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


    PM> Install-Package Aspose.Page.Cpp

Steps to Convert PS to JPEG using C++

Aspose.Page makes it easy for the developers to load and convert PS files to JPEG in just a few lines of code.

  1. Load PS file with Aspose.Page for C++.
  2. Create the object of ImageSaveOptions Class and set image format as ImageFormat::Jpeg .
  3. Get bytes array of image calling SaveAsImage with defined options.
  4. Save image by writing image bytes to output stream.
This code sample explains PS to JPEG C++ Conversion
// 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) is a powerful page‑description language that combines text and graphics in a device‑independent way. It is widely supported by printers and professional image editors. PS files contain the rendering instructions for the page and can be converted to PDF, EPS, or raster formats.

JPEG What is JPEG File Format

JPEG (Joint Photographic Experts Group) uses lossy compression to achieve a good balance between image quality and file size, making it ideal for photographs and web images.