既存のPDFからテーブルを削除する

テーブルを削除するには、TableAbsorberクラスを使用して既存のPDF内のテーブルを取得し、次にRemoveを呼び出す必要があります。

以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。

PDFドキュメントからテーブルを削除する

PDFドキュメントからテーブルを削除するために、既存のTableAbsorberクラスに新しい関数、すなわちRemove()を追加しました。アブソーバーがページ上のテーブルを正常に見つけると、それらを削除する能力を持つようになります。以下のコードスニペットは、PDFドキュメントからテーブルを削除する方法を示しています:

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RemoveTable()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "Table_input.pdf"))
    {
        // Create TableAbsorber object to find tables
        var absorber = new Aspose.Pdf.Text.TableAbsorber();

        // Visit first page with absorber
        absorber.Visit(document.Pages[1]);

        // Get first table on the page
        Aspose.Pdf.Text.AbsorbedTable table = absorber.TableList[0];

        // Remove the table
        absorber.Remove(table);

        // Save PDF document
        document.Save(dataDir + "RemoveTable_out.pdf");
    }
}

PDFドキュメントから複数のテーブルを削除する

時には、PDFドキュメントに複数のテーブルが含まれている場合があり、複数のテーブルを削除する必要があるかもしれません。PDFドキュメントから複数のテーブルを削除するには、以下のコードスニペットを使用してください:

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void RemoveMultipleTables()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Tables();

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "Table_input2.pdf"))
    {
        // Create TableAbsorber object to find tables
        var absorber = new Aspose.Pdf.Text.TableAbsorber();

        // Visit second page with absorber
        absorber.Visit(document.Pages[1]);

        // Get copy of table collection
        Aspose.Pdf.Text.AbsorbedTable[] tables = new Aspose.Pdf.Text.AbsorbedTable[absorber.TableList.Count];
        absorber.TableList.CopyTo(tables, 0);

        // Loop through the copy of collection and removing tables
        foreach (var table in tables)
        {
            absorber.Remove(table);
        }

        // Save PDF document
        document.Save(dataDir + "RemoveMultipleTables_out.pdf");
    }
}