แปลง PS, EPS และ XPS

ปลดล็อกศักยภาพสูงสุดของแอปพลิเคชัน C++ ของคุณด้วยโซลูชัน API ที่หลากหลายของเรา! แปลงไฟล์ PS, EPS และ XPS เป็น PDF คุณภาพสูงและรูปภาพที่น่าทึ่งได้อย่างราบรื่นด้วยโซลูชัน API อเนกประสงค์สำหรับ C++!

 

ค้นพบศักยภาพสูงสุดของแอปพลิเคชัน C++ ของคุณด้วยโซลูชัน API ดั้งเดิมที่ใช้งานได้หลากหลายของเรา! แปลงไฟล์ PS, EPS และ XPS ให้เป็น PDF คุณภาพสูงและรูปภาพที่น่าทึ่งได้อย่างรวดเร็วและง่ายดาย ไม่ว่าคุณจะต้องการการแปลงเอกสารที่แม่นยำหรือเนื้อหาภาพที่สมบูรณ์แบบ API ของเราช่วยให้กระบวนการง่ายขึ้น โดยมอบเครื่องมือเพื่อปรับปรุงโครงการของคุณได้อย่างง่ายดาย ปรับปรุงการจัดการเอกสารของคุณและเติมชีวิตใหม่ให้กับภาพของคุณ สัมผัสความมหัศจรรย์ของการแปลงเอกสาร PostScript (PS) และ Encapsulated PostScript (EPS) รวมถึงเอกสาร XPS เป็น PDF และรูปภาพด้วย C++ API ของเรา พร้อมที่จะเปลี่ยนแปลงเอกสารของคุณหรือยัง? ลองใช้รุ่นทดลองใช้ฟรีหรือซื้อตอนนี้และยกระดับเนื้อหาของคุณตั้งแต่วันนี้!

นักโปรแกรมสามารถใช้งานได้อย่างง่ายดายสำหรับการประมวลผลเอกสาร PostScript และ XPS แบบกลุ่ม แม้กระทั่งจัดการองค์ประกอบแคนวาส (canvases), เส้นทาง (paths) และกลิฟ (glyphs) ตลอดจนจัดการรูปร่างกราฟิกเวกเตอร์และสตริงข้อความ

โซลูชัน API สำหรับ C++ ที่นี่ช่วยให้คุณแปลงไฟล์รูปแบบ PDL เช่น PS, EPS และ XPS ได้โดยการเขียนโปรแกรม แต่อาจเป็นประโยชน์หากได้ดูและลองใช้โซลูชันข้ามแพลตฟอร์มที่พัฒนาขึ้นบน API ดั้งเดิมเหล่านี้ นี่คือสถานการณ์จำลองบางส่วนของการแปลง เช่น EPS เป็นรูปภาพ, EPS เป็น PDF, PostScript เป็น PDF, PostScript เป็นรูปภาพ, XPS เป็นรูปภาพ และ XPS เป็น PDF

แปลง PostScript (PS, EPS) เป็นรูปภาพผ่าน C++

ไลบรารี C++ ช่วยให้สามารถแปลงไฟล์ PostScript (PS) และ Encapsulated PostScript (EPS) เป็นรูปภาพบนแพลตฟอร์ม Windows, Linux และ macOS กระบวนการคือ:

  1. โหลดเอกสารโดยใช้ constructor ของคลาส PsDocument โดยใช้สตรีมไฟล์อินพุตหรือชื่อไฟล์เป็นพารามิเตอร์
  2. สร้างวัตถุ ImageSaveOptions Class และเริ่มต้นด้วยการตั้งค่าที่จำเป็น เรียก set_ImageFormat เพื่อตั้งค่ารูปแบบรูปภาพเป็นค่าของ ImageFormat
  3. บันทึกแต่ละหน้าของไฟล์อินพุตลงในอาร์เรย์ไบต์ของรูปภาพด้วย SaveAsImage
รหัส C++ สำหรับการแปลง EPS เป็นรูปภาพ
    // 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());
        }
    }
 

การแปลง PostScript เป็น PDF ผ่าน C++

กระบวนการแปลง PostScript เป็น PDF นั้นง่ายพอๆ กับการแปลง PostScript เป็นรูปภาพ:

  1. โหลดเอกสารโดยใช้ constructor ของคลาส PsDocument โดยใช้สตรีมไฟล์อินพุตหรือชื่อไฟล์เป็นพารามิเตอร์
  2. สร้างวัตถุของ PdfSaveOptions Class เพื่อกำหนดการตั้งค่าเพิ่มเติม เช่น AdditionalFontsFolder และค่า SuppressError เป็นต้น
  3. เรียกวิธี SaveAsPdf เพื่อแปลงไฟล์เป็น PDF
รหัส C++ สำหรับการแปลง PostScript เป็น PDF
    // 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());
        }
    }
 

แปลง XPS เป็นรูปภาพผ่าน C++

C++ XPS Processing API จัดการกับการแปลง XPS เป็นรูปภาพ ได้แก่ BMP, JPG, TIFF, PNG และอื่นๆ รวมถึงการแปลง XPS เป็น PDF บนระบบปฏิบัติการ Windows และ Linux กระบวนการแปลง XPS เป็นรูปภาพคือ:

  1. สร้างอินสแตนซ์ของ XpsDocument Class ด้วยชื่อไฟล์อินพุตและ XpsLoadOptions เป็นพารามิเตอร์คอนสตรัคเตอร์
  2. สร้างตัวเลือกการบันทึกเป็นอินสแตนซ์ของคลาสใดคลาสหนึ่งจาก Aspose::Page::XPS::Presentation::Image
  3. เรียกวิธี SaveAsImage ของเอกสาร XPS เพื่อบันทึกแต่ละหน้าของเอกสารลงในอาร์เรย์ไบต์ของรูปภาพ
รหัส C++ สำหรับการแปลง XPS เป็นรูปภาพ
    // 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());
                }
            }
        }
    }

 

แปลง XPS เป็น PDF ผ่าน C++

C++ XPS Processing API จัดการกับการแปลง XPS เป็นรูปภาพ ได้แก่ BMP, JPG, TIFF, PNG และอื่นๆ รวมถึงการแปลง XPS เป็น PDF บนระบบปฏิบัติการ Windows และ Linux กระบวนการแปลง XPS เป็น PDF คือ:

  1. กำหนดสตรีมเอาต์พุตสำหรับเอาต์พุต PDF
  2. สร้างอินสแตนซ์ของ XpsDocument Class ด้วยชื่อไฟล์อินพุตและ XpsLoadOptions เป็นพารามิเตอร์คอนสตรัคเตอร์
  3. ระบุตัวเลือกการบันทึกเฉพาะสำหรับ PDF เช่น TextCompression, ImageCompression และ JpegQualityLevel โดยใช้ PdfSaveOptions
  4. สุดท้าย แปลงเอกสาร XPS เป็น PDF โดยใช้วิธี SaveAsPdf วิธีใดก็ได้
รหัส C++ สำหรับการแปลง XPS เป็น PDF
    // 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. ฉันสามารถแปลง Postscript ด้วยโซลูชัน API นี้ได้หรือไม่

Aspose.Page มีฟังก์ชันที่ช่วยให้คุณแปลงไฟล์ PS, XPS และ EPS เป็นรูปแบบอื่นทางออนไลน์หรือโดยทางโปรแกรม หากคุณต้องการแปลงไฟล์ออนไลน์ทันที คุณอาจต้องการใช้ Page Description Language format files Converter แอปพลิเคชันข้ามแพลตฟอร์ม

2. ตัวแปลงภาษาใดที่คำอธิบายเพจรองรับ?

ฟังก์ชันการแปลงนี้สนับสนุนไฟล์ที่มีนามสกุล .ps, .eps และ .xps PDL ที่มีชื่อเสียงเช่น PDF และ SVG จะแสดงเป็นโซลูชันแยกต่างหากใน Aspose.products

3. ฟังก์ชั่นฟรีหรือไม่?

ตัวแปลงข้ามแพลตฟอร์ม นั้นฟรี เมื่อสำหรับโซลูชัน API คุณสามารถทดลองใช้งานฟรีแล้วซื้อผลิตภัณฑ์หากจำเป็น