转换 PS、EPS 和 XPS

利用我们多功能的 API 解决方案释放 C++ 应用程序的全部潜力!使用我们专为 C++ 设计的多功能 API 解决方案,将 PS、EPS 和 XPS 文件无缝转换为高质量的 PDF 和令人惊叹的图像!

 

利用我们多功能的原生 API 解决方案探索 C++ 应用程序的全部潜力!快捷简便地将 PS、EPS 和 XPS 文件转换为高质量的 PDF 和令人惊叹的图像。无论您需要精确的文档转换还是完美的视觉内容,我们的 API 都能简化流程,为您提供毫不费力增强项目的工具。改善您的文档管理并为您的视觉内容注入新的活力。体验使用我们的 C++ API 将 PostScript (PS) 和 Encapsulated PostScript (EPS) 以及 XPS 文档转换为 PDF 和图像的神奇之处。准备好转换您的文档了吗?立即尝试我们的免费试用版或购买,以此提升您的内容价值!

程序员可以轻松地将其用于 PostScript 和 XPS 文档的批处理,甚至可以操作画布、路径和字形元素,并处理矢量图形形状和文本字符串。

这里的 C++ API 解决方案允许您以编程方式转换 PS、EPS 和 XPS 等 PDL 格式的文件,但您可能会发现查看和尝试在这些原生 API 上开发的跨平台解决方案很有用。以下是一些转换场景,例如 EPS 转换为图像、EPS 转换为 PDF、PostScript 转换为 PDF、PostScript 转换为图像、XPS 转换为图像以及 XPS 转换为 PDF。

通过 C++ 将 PostScript (PS, EPS) 转换为图像。

C++ 库允许在 Windows、Linux 和 macOS 平台上将 PostScript (PS) 和 Encapsulated PostScript (EPS) 文件转换为图像。流程如下:

  1. 使用以输入文件流或文件名作为参数的 PsDocument构造函数 加载文档。
  2. 创建 ImageSaveOptions 类 对象并使用所需设置进行初始化。调用 set_ImageFormat 将图像格式设置为 ImageFormat 的值。
  3. 使用 SaveAsImage 将每个输入文件页面保存到图像字节数组中。
EPS 转换为图像的 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"inputForImage.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::Png);
    
    // 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());
        }
    }
 

通过 C++ 进行 PostScript 到 PDF 的转换。

将 PostScript 转换为 PDF 的过程与 PostScript 转换为图像一样简单:

  1. 使用以输入文件流或文件名作为参数的 PsDocument构造函数 加载文档。
  2. 创建 PdfSaveOptions 类 的对象以定义其他设置,例如 AdditionalFontsFolder 和 SuppressError 值等。
  3. 调用 SaveAsPdf 方法进行 PDF 文件转换。
PostScript 到 PDF 转换的 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<PdfSaveOptions> options = System::MakeObject<PdfSaveOptions>(suppressErrors);
    // 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}"}));
    // Default page size is 595x842 and it is not mandatory to set it in PdfSaveOptions
    // But if you need to specify sizeuse following line
    //PdfSaveOptions options = new PdfSaveOptions(suppressErrorsnew, Aspose.Page.Drawing.Size(595x842));
    // or
    //saveOptions.Size = new Aspose.Page.Drawing.Size(595x842);
    
    // Save document as PDF
    document->SaveAsPdf(dataDir + u"outputPDF_out.pdf", options);
    
    //Review errors
    if (suppressErrors)
    {
        for (auto&& ex : System::IterateOver(options->get_Exceptions()))
        {
            System::Console::WriteLine(ex->get_Message());
        }
    }
 

通过 C++ 将 XPS 转换为图像。

C++ XPS 处理 API 在 Windows 和基于 Linux 的系统上处理 XPS 到图像(包括 BMP、JPG、TIFF、PNG 等)的转换以及 XPS 到 PDF 的转换。将 XPS 转换为图像的过程如下:

  1. 使用输入文件名和 XpsLoadOptions 作为构造函数参数创建 XpsDocument 类 实例。
  2. 创建保存选项作为 Aspose::Page::XPS::Presentation::Image 中一个类的实例。
  3. 调用 XPS 文档的 SaveAsImage 方法将每个文档页面保存到图像字节数组中。
XPS 转换为图像的 C++ 代码
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
    
    //Outut file 
    System::String outputFileName = dataDir + u"XPStoImage_out.bmp";
    
    // Load XPS document form the XPS file
    System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>());
    
    // Initialize options object with necessary parameters.
    System::SharedPtr<BmpSaveOptions> options = System::MakeObject<BmpSaveOptions>();
    options->set_SmoothingMode(System::Drawing::Drawing2D::SmoothingMode::HighQuality);
    options->set_Resolution(300);
    options->set_PageNumbers(System::MakeArray<int32_t>({1, 2, 6}));
    
    // Save XPS document to the images byte arrays. The first dimension is for inner documents
    // and the second one is for pages within inner documents.
    System::ArrayPtr<System::ArrayPtr<System::ArrayPtr<uint8_t>>> imagesBytes = document->SaveAsImage(options);
    
    // Iterate through document partitions (fixed documents, in XPS terms)
    for (int32_t i = 0; i < imagesBytes->get_Length(); i++)
    {
        // Iterate through partition pages
        for (int32_t j = 0; j < imagesBytes[i]->get_Length(); j++)
        {
            // Initialize image output stream
            {
                System::SharedPtr<System::IO::Stream> imageStream = System::IO::File::Open(System::IO::Path::GetDirectoryName(outputFileName) + System::IO::Path::DirectorySeparatorChar + System::IO::Path::GetFileNameWithoutExtension(outputFileName) + u"_" + (i + 1) + u"_" + (j + 1) + System::IO::Path::GetExtension(outputFileName), System::IO::FileMode::Create, System::IO::FileAccess::Write);
                // Clearing resources under 'using' statement
                System::Details::DisposeGuard<1> __dispose_guard_0({ imageStream});
                // ------------------------------------------
                
                try
                {
                    imageStream->Write(imagesBytes[i][j], 0, imagesBytes[i][j]->get_Length());
                }
                catch(...)
                {
                    __dispose_guard_0.SetCurrentException(std::current_exception());
                }
            }
        }
    }

 

通过 C++ 将 XPS 转换为 PDF。

C++ XPS 处理 API 在 Windows 和基于 Linux 的系统上处理 XPS 到图像(包括 BMP、JPG、TIFF、PNG 等)的转换以及 XPS 到 PDF 的转换。将 XPS 转换为 PDF 的阶段包括:

  1. 定义 PDF 输出的输出流。
  2. 使用输入文件名和 XpsLoadOptions 作为构造函数参数创建 XpsDocument 类 实例。
  3. 使用 PdfSaveOptions 指定 PDF 特定的保存选项,例如 TextCompression、ImageCompression 和 JpegQualityLevel。
  4. 最后使用任意一个 SaveAsPdf 方法将 XPS 文档转换为 PDF。
XPS 到 PDF 转换的 C++ 代码
    // The path to the documents directory.
    System::String dataDir = RunExamples::GetDataDir_WorkingWithDocumentConversion();
    
    // Initialize PDF output stream
    {
        System::SharedPtr<System::IO::Stream> pdfStream = System::IO::File::Open(dataDir + u"XPStoPDF_out.pdf", System::IO::FileMode::OpenOrCreate, System::IO::FileAccess::Write);
        // Clearing resources under 'using' statement
        System::Details::DisposeGuard<1> __dispose_guard_0({ pdfStream});
        // ------------------------------------------
        
        try
        {
            // Load XPS document form the XPS file
            System::SharedPtr<XpsDocument> document = System::MakeObject<XpsDocument>(dataDir + u"input.xps", System::MakeObject<XpsLoadOptions>());
            
            // Initialize options object with necessary parameters.
            System::SharedPtr<Aspose::Page::XPS::Presentation::Pdf::PdfSaveOptions> options = System::MakeObject<Aspose::Page::XPS::Presentation::Pdf::PdfSaveOptions>();
            options->set_JpegQualityLevel(100);
            options->set_ImageCompression(Aspose::Page::XPS::Presentation::Pdf::PdfImageCompression::Jpeg);
            options->set_TextCompression(Aspose::Page::XPS::Presentation::Pdf::PdfTextCompression::Flate);
            options->set_PageNumbers(System::MakeArray<int32_t>({1, 2, 6}));
            
            document->SaveAsPdf(pdfStream, options);
        }
        catch(...)
        {
            __dispose_guard_0.SetCurrentException(std::current_exception());
        }
    }



FAQ

1. 我可以用这个 API 解决方案转换 Postscript 吗?

Aspose.Page 具有允许您在线或以编程方式将 PS、XPS 和 EPS 文件转换为其他格式的功能。如果您需要立即在线转换您的文件,您可以使用 页面描述语言格式文件转换器 跨平台应用程序。

2. 转换器支持哪些页面描述语言?

此转换功能支持具有 .ps、.eps 和 .xps 扩展名的文件。 PDF 和 SVG 等著名的 PDL 在 Aspose.products 中表示为单独的解决方案

3. 功能是免费的吗?

跨平台转换器 是免费的,对于 API 解决方案,您可以获得免费试用版,然后在需要时购买产品。

  

Support and Learning Resources