Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
为了移除表格,我们需要使用TableAbsorber类来获取现有PDF中的表格,然后调用Remove。
以下代码片段也适用于Aspose.PDF.Drawing库。
我们在现有的TableAbsorber类中添加了新功能,即Remove(),以便从PDF文档中移除表格。一旦吸收器成功找到页面上的表格,它就能够将其移除。请查看以下代码片段,展示如何从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文档中移除多个表格,请使用以下代码片段:
// 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");
}
}
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.