Dear team,
I have a word document which has a place holder @table. I have converted the word to pdf document and now want to create a table.
The table should contain editable rows and it should be placed at @table place holder location in pdf.
Could you please help me to accomplish the task.
Please find the attached files for reference.
Regards,
Satya
Hi Satya,
Hi Shahbaz,
Thank you for providing the information.
I am able to get the rectangle coordinates of @table place holder, but am not able to create a table like the one present in the attachment at captured co-ordinates.
Please tell me which class to be used to create a table and how to pass captured rectangular coordinates.
Also, will the data in table be split to multiple pages if row count is more or do we need check for the end of page condition and split the rows while generating the table.
Please advise.
Regards,
Satya
Hi Satya,
Thanks for contacting support.
In order to render the table on coordinates returned by search results of TextSegment, please try using following code snippet.
[C#]
// Open document
Document pdfDocument = new Document("c:/pdftest/Demo_Document_Final_1 (1).pdf");
// Create TextAbsorber object to find all instances of the input search phrase
Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber("@table");
// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);
// Get the extracted text fragments
Aspose.Pdf.Text.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
double SearchString_XIndent = 0;
double SearchString_YIndent = 0;
// Loop through the fragments
foreach (Aspose.Pdf.Text.TextFragment textFragment in textFragmentCollection)
{
foreach (Aspose.Pdf.Text.TextSegment textSegment in textFragment.Segments)
{
Console.WriteLine("XIndent : {0} ", textSegment.Position.XIndent);
SearchString_XIndent = textSegment.Position.XIndent;
Console.WriteLine("YIndent : {0} ", textSegment.Position.YIndent);
SearchString_YIndent = textSegment.Position.YIndent;
}
}
// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
table.Left = (float)SearchString_XIndent;
table.Top = (float)(pdfDocument.Pages[1].PageInfo.Height - SearchString_YIndent);
// Create a loop to add 10 rows
for (int row_count = 1; row_count < 10; row_count++)
{
// Add row to table
Aspose.Pdf.Row row = table.Rows.Add();
// Add table cells
row.Cells.Add("Column (" + row_count + ", 1)");
row.Cells.Add("Column (" + row_count + ", 2)");
row.Cells.Add("Column (" + row_count + ", 3)");
}
// Add table object to first page of input document
pdfDocument.Pages[1].Paragraphs.Add(table);
// Save updated document containing table object
pdfDocument.Save(“c:/ pdftest / Table_in_PDF.pdf”);
Dear team,
I have tried to generate the table with the code that you have provided and can see that the table is read-only.
I want a table in Pdf document with editable cell content.
Also, when the table is generated dynamically, the table is overlapping with the content present in the existing pdf document.
Is there any way to automatically adjust the content in the pdf table to fit the dynamic table.?
Regards,
Satya
Hi Satya,
Thanks for sharing the details.
The solution to have editable cell contents is to add TextFields inside respective table cells. However when using following code snippet, we have observed that Form fields are not rendering inside table cells. For the sake of correction, I have logged it as PDFNET-42778 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.
[C#]
// Open document
Document pdfDocument = new Document("c:/pdftest/Demo_Document_Final_1.pdf");
// Create TextAbsorber object to find all instances of the input search phrase
Aspose.Pdf.Text.TextFragmentAbsorber textFragmentAbsorber = new Aspose.Pdf.Text.TextFragmentAbsorber("@table");
// Accept the absorber for all the pages
pdfDocument.Pages.Accept(textFragmentAbsorber);
// Get the extracted text fragments
Aspose.Pdf.Text.TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
double SearchString_XIndent = 0;
double SearchString_YIndent = 0;
// Loop through the fragments
foreach (Aspose.Pdf.Text.TextFragment textFragment in textFragmentCollection)
{
foreach (Aspose.Pdf.Text.TextSegment textSegment in textFragment.Segments)
{
Console.WriteLine("XIndent : {0} ", textSegment.Position.XIndent);
SearchString_XIndent = textSegment.Position.XIndent;
Console.WriteLine("YIndent : {0} ", textSegment.Position.YIndent);
SearchString_YIndent = textSegment.Position.YIndent;
}
}
// Initializes a new instance of the Table
Aspose.Pdf.Table table = new Aspose.Pdf.Table();
// Set the table border color as LightGray
table.Border = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
// Set the border for table cells
table.DefaultCellBorder = new Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, .5f, Aspose.Pdf.Color.FromRgb(System.Drawing.Color.LightGray));
table.Left = (float)SearchString_XIndent;
table.Top = (float)(pdfDocument.Pages[1].PageInfo.Height - SearchString_YIndent);
// Create a loop to add 10 rows
TextBoxField textBoxField = new TextBoxField(pdfDocument, new Aspose.Pdf.Rectangle(10, 10, 20, 20));
for (int row_count = 1; row_count < 10; row_count++)
{
// Add row to table
Aspose.Pdf.Row row = table.Rows.Add();
// row.Cells[1].Margin.Left,row.Cells[1].Margin.Bottom, row.Cells[1].Width, row.FixedRowHeight-1));
textBoxField.PartialName = "textbox1";
textBoxField.Name = "Text1";
textBoxField.Value = "Text Box";
// TextBoxField.Border = new Border(
Aspose.Pdf.Annotations.Border border = new Aspose.Pdf.Annotations.Border(textBoxField);
border.Width = 5;
border.Dash = new Aspose.Pdf.Annotations.Dash(1, 1);
textBoxField.Border = border;
// Add table cells
row.Cells.Add().Paragraphs.Add(textBoxField); // "Column (" + row_count + ", 1)");
row.Cells.Add("Column (" + row_count + ", 2)");
row.Cells.Add("Column (" + row_count + ", 3)");
}
pdfDocument.Form.Add(textBoxField, 1);
// Add table object to first page of input document
pdfDocument.Pages[1].Paragraphs.Add(table);
// Save updated document containing table object
pdfDocument.Save("c:/pdftest/Table_in_PDF.pdf");
Hi Satya,Satya1992:Also, when the table is generated dynamically, the table is overlapping with the content present in the existing pdf document.Is there any way to automatically adjust the content in the pdf table to fit the dynamic table.?
Hello, is there any follow up on issue PDFNET-42779? I need to insert a table at a specific point and have it not overlap the following text. Any possible solution would help.
We are afraid PDFNET-42779 has not been resolved yet. We have recorded your concerns and will update you as soon as any significant update is available.
Was this fixed?
Regretfully, these tickets could not get resolved yet. However, you will surely be notified once resolution is made against them. We apologize for your inconvenience.