แก้ไขไฟล์ PDF โดยใช้ C++

ข้อมูลการแก้ไขที่ละเอียดอ่อนของเอกสาร PDFใช้ Aspose.PDF สำหรับ C++ เพื่อแก้ไขเอกสาร PDF แบบโปรแกรม

วิธีแก้ไขไฟล์ PDF โดยใช้ห้องสมุด C++

ในการแก้ไขไฟล์ PDF เราจะใช้ Aspose.PDF for C++ API ซึ่งเป็น API การจัดการเอกสารที่อุดมไปด้วยคุณสมบัติ ทรงพลัง และใช้งานง่ายสำหรับแพลตฟอร์ม cppเปิดตัวจัดการแพคเกจ NuGet ค้นหาAspose.PDF และติดตั้งคุณอาจใช้คำสั่งต่อไปนี้จากคอนโซลตัวจัดการแพคเกจ

แก้ไขเอกสาร PDF ผ่าน C++


คุณต้อง Aspose.PDF for C++ เพื่อลองใช้รหัสในสภาพแวดล้อมของคุณ

1.โหลด PDF ด้วยอินสแตนซ์ของเอกสาร 1.สร้างวัตถุ TextFragmentAbsorber ด้วยคำค้นหาเป็นอาร์กิวเมนต์ 1.ตั้งค่าตัวเลือกการค้นหา 1.ลูปผ่านแต่ละส่วนที่รวบรวมเพื่อแก้ไข 1.บันทึกไฟล์ PDF

แก้ไขไฟล์ PDF - C++


    // Load PDF file
    auto pdfDocument = MakeObject<Document>(u"sourceFile.pdf");

    // Create TextAbsorber object to find all instances of the input search phrase
    auto textFragmentAbsorber = MakeObject<TextFragmentAbsorber>(u"Document");

    // Accept the absorber for all the pages
    pdfDocument->get_Pages()->Accept(textFragmentAbsorber);

    // Get the extracted text fragments
    auto textFragmentCollection = textFragmentAbsorber->get_TextFragments();

    // Loop through the fragments
    for (auto textFragment : textFragmentCollection){
        // Update text and other properties
        textFragment->set_Text(u"UPDATED TEXT");
        textFragment->get_TextState()->set_Font(FontRepository::FindFont(u"TimesNewRoman"));
        textFragment->get_TextState()->set_FontSize(22);
    }

    // Save the resulting PDF document.
    pdfDocument->Save(u"outputFile.pdf");