We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Place a textbox within a specific cell in a table

Good Day


We are currently generating a table and we want to make the fields within a specific column editable. I want to place textboxes within the cells of the editable column but the problem is that I can’t find the coordinates of the cell on the page so that I can position the TextBox. Currently when I look at the rectangle location of the TextFragment in the cell, it gives me the coordinates relative to the cell and not relative to the page so the TextBox ends up being at the bottom left corner of the page.

To summarize:
- How do a place a TextBox inside a specific cell of a table.
- How do I set the size of the TextBox to the size of the cell.

We are coding in C#.

Thank you in advance.

Hi Pieter,


Thanks for your inquiry. Please check sample code snippet for adding textboxfield in Tables cell and how to fit it into the cell. Hopefully it will help you to accomplish the task.

Document doc = new
Document();<o:p></o:p>

Aspose.Pdf.Page page = doc.Pages.Add();

Aspose.Pdf.Table table1 = new Aspose.Pdf.Table();

table1.ColumnWidths = "120 120 120";

page.Paragraphs.Add(table1);

Aspose.Pdf.Row row1 = table1.Rows.Add();

row1.FixedRowHeight = 15;

Aspose.Pdf.Cell cell1 = row1.Cells.Add("Name");

Aspose.Pdf.Cell cell2 = row1.Cells.Add("City");

Aspose.Pdf.Cell cell3 = row1.Cells.Add("State");

TextBoxField field = new TextBoxField();

field.PartialName = "TextBoxName";

field.Value = "John";

field.Width = 120;

field.Height = 15;

field.Multiline = true;

TextBoxField field2 = new TextBoxField();

field2.PartialName = "TextBoxCity";

field2.Value = "New York";

field2.Width = 120;

field2.Height = 15;

TextBoxField field3 = new TextBoxField();

field3.PartialName = "TextBoxState";

field3.Value = "NY";

field3.Width = 120;

field3.Height = 15;

Aspose.Pdf.Row row2 = table1.Rows.Add();

Aspose.Pdf.Cell cell4 = row2.Cells.Add();

Aspose.Pdf.Cell cell5 = row2.Cells.Add();

Aspose.Pdf.Cell cell6 = row2.Cells.Add();

cell4.Paragraphs.Add(field);

cell5.Paragraphs.Add(field2);

cell6.Paragraphs.Add(field3);

Aspose.Pdf.Row row3 = table1.Rows.Add();

row3.FixedRowHeight = 80;

//Aspose.Pdf.Cell commentTbCell = row3.Cells.Add();

Aspose.Pdf.Cell commentTbCell = new Aspose.Pdf.Cell();

commentTbCell.ColSpan = 3;

TextBoxField textBoxField11 = new TextBoxField();

textBoxField11.PartialName = "Comment_tb";

textBoxField11.Height = 70;

textBoxField11.Multiline = true;

textBoxField11.Width = 360;

commentTbCell.Paragraphs.Add(textBoxField11);

row3.Cells.Add(commentTbCell);

//Save modified PDF

doc.Save(myDir + "PDFFormOutput.pdf");

Please feel free to contact us for any further assistance.


Best Regards,

Thanks for your response. Greatly appreciated.

Hi Pieter,


Thanks for your feedback. It is good to to know that sample code snippet helps you to accomplish the task.

Please keep using our API and feel free to ask any question or concern, we will be more than happy to extend our support.

Best Regards,

Hello,

what if i dont know the height of the table row in which i want to add the Textboxfield, because content is written dynamically in that row, for example in a preceding cell? The Textbox size should be the same size then. How can i do that?

@schiepe

Thanks for contacting support.

You may add TextboxField without specifying height and width and it will be added with default dimensions. However, in case you are facing any issue while achieving your requirement, please share complete sample code snippet along with sample PDF document. We will test the scenario in our environment and share our feedback accordingly.