@asad.ali
I am attaching my original pdf as well as the updated pdf here.
Also this is my code
foreach (var page in pdfDocument.Pages)
{
TableAbsorber tableAbsorber = new TableAbsorber();
tableAbsorber.Visit(page);
double SearchString_XIndent = 0;
double SearchString_YIndent = 0;
foreach (var table in tableAbsorber.TableList)
{
var cornerText = table.RowList[0].CellList[0]?.TextFragments[1]?.Segments[1];
// Is there a better way to grab the text fragments of the row when the row expands to the next page?
if (cornerText != null && cornerText.Text.StartsWith("Preliminary") || cornerText.Text.StartsWith("Patient:"))
{
if (cornerText != null && cornerText.Text.StartsWith("Preliminary"))
{
Aspose.Pdf.Table newtable = new Aspose.Pdf.Table
{
DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.Gray)
};
SearchString_XIndent = cornerText.BaselinePosition.XIndent;
SearchString_YIndent = cornerText.BaselinePosition.YIndent;
newtable.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;
newtable.Alignment = HorizontalAlignment.FullJustify;
newtable.IsKeptWithNext = true;
newtable.RepeatingRowsCount = 2;
newtable.Left = (float)SearchString_XIndent;
newtable.Top = (float)(page.PageInfo.Height - SearchString_YIndent - SearchString_XIndent);
// Create MarginInfo object and set its left, bottom, right and top margins
Aspose.Pdf.MarginInfo margin = new Aspose.Pdf.MarginInfo();
margin.Top = 5f;
margin.Left = 5f;
margin.Right = 5f;
margin.Bottom = 5f;
//Add row1
Aspose.Pdf.Row row1 = newtable.Rows.Add();
row1.Cells.Add();
TextFragment heading = new TextFragment("Preliminary Findings");
heading.TextState.FontSize = 12;
heading.TextState.Font = FontRepository.FindFont("Arial Narrow");
heading.TextState.FontStyle = FontStyles.Bold;
row1.Cells[0].Paragraphs.Add(heading);
//Add row2
Aspose.Pdf.Row row2 = newtable.Rows.Add();
row2.Cells.Add();
TextFragment mytext = new TextFragment("the convergence of the digital and physical worlds, has emerged as one of the fundamental trends underlying the digital transformation " +
"of business and the economy. From the fitness trackers we wear to the smart thermostats we use in our homes to the fleet-management solutions that tell us when our packages " +
"will arrive to the sensors that promote increased energy efficiency or monitor natural disasters resulting from climate change, the IoT is now embedded in the lives of " +
"consumers and the operations of enterprises and governments. In 2015, the McKinsey Global Institute published a research report entitled " +
"The Internet of Things: Mapping the value beyond the hype.");
mytext.TextState.Font = FontRepository.FindFont("Arial Narrow");
mytext.TextState.FontSize = 8;
mytext.HorizontalAlignment = HorizontalAlignment.Left;
row2.Cells[0].Paragraphs.Add(mytext);
row2.Cells[0].IsWordWrapped = true;
//Add row3
Aspose.Pdf.Row row3 = newtable.Rows.Add();
row3.Cells.Add();
TextFragment mytext2 = new TextFragment("End of Preliminary Findings");
mytext2.TextState.Font = FontRepository.FindFont("Arial Narrow");
mytext2.TextState.FontSize = 8;
mytext2.HorizontalAlignment = HorizontalAlignment.Center;
row2.Cells[0].Paragraphs.Add(mytext2);
page.Paragraphs.Add(newtable); //Add new table
}
string txt1 = "";
foreach (AbsorbedRow row in table.RowList)
{
foreach (AbsorbedCell cell in row.CellList)
{
TextFragmentCollection textFragmentCollection = cell.TextFragments;
foreach (TextFragment fragment in textFragmentCollection)
{
foreach (TextSegment seg in fragment.Segments)
{
txt1 += seg.Text;
seg.Text = " ";
}
Console.WriteLine(txt1);
}
}
}
var mystring1 = txt1;
tableAbsorber.Remove(table);
pdfDocument.ProcessParagraphs();
break;
}
}
}