แก้ไขรูปแบบ PDF ใน C#

เอกสาร PDF ที่มีประสิทธิภาพสูงพื้นเมืองและมีประสิทธิภาพสูงข้อมูลการแก้ไขข้อมูลที่ละเอียดอ่อนโดยใช้ Aspose.PDF ฝั่งเซิร์ฟเวอร์สำหรับ C# API โดยไม่ต้องใช้ซอฟต์แวร์ใด ๆ เช่น Microsoft หรือ Adobe PDF

วิธีการแก้ไขไฟล์ PDF โดยใช้ไลบรารี C#

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

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


คุณจำเป็นต้อง Aspose.PDF for .NET ที่จะลองรหัสในสภาพแวดล้อมของคุณ

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");