การแก้ไข PDF

ค้นหาและลบเนื้อหาในเอกสาร PDF ด้วยแอพและ API ข้ามแพลตฟอร์มฟรี

วิธีแก้ไขไฟล์ PDF

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

แก้ไขเอกสาร PDF


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

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

แก้ไข PDF - C#


    Document doc = new Document(dataDir + "test.pdf");

    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(searchTerm);
    TextSearchOptions textSearchOptions = new TextSearchOptions(true);
    textFragmentAbsorber.TextSearchOptions = textSearchOptions;

    doc.Pages.Accept(textFragmentAbsorber);
    TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
    foreach (TextFragment textFragment in textFragmentCollection)
{
    Page page = textFragment.Page;
    Rectangle annotationRectangle = textFragment.Rectangle;

    Annotations.RedactionAnnotation annot = new Annotations.RedactionAnnotation(page, annotationRectangle);
    annot.FillColor = Color.Black;
    doc.Pages[textFragment.Page.Number].Annotations.Add(annot, true);
    annot.Redact();
}
    doc.Save(dataDir + "output.pdf");