PDF table generation

Hi

please refer below attachment. i want to create table like attached image.
I am using table object but not able to create like attached format.

1. how to create exact table format
2. how to use superscript number
3. how to display TM like in image
4. how to use same font and size, i am using font, but problem in font repository
5. you see the appendix information, user entered just information without line break, how to achieve this one
6. how to set background color for appendix information


if you give some sample like below image format that will be very useful for me. i am using aspose version 16.12.0

cshanmugasundaram:

  1. how to create exact table format

Hi,

Thanks for contacting support.

Please follow the instructions specified over Add Table in Existing PDF Document.

cshanmugasundaram:

  1. how to use superscript number

In order to render SuperScript text, please try using HTML text inside table cell.

cshanmugasundaram:

  1. how to display TM like in image

Please use HTML text and place it inside table cell.

[C#]

// Load source PDF document
Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
doc.Pages.Add();

// 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));

HtmlFragment titel = new HtmlFragment("CyflufenamidTM");

// 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();
    row.Cells[0].Paragraphs.Add(titel);
    row.Cells[0].BackgroundColor = Aspose.Pdf.Color.Green;

    row.Cells.Add("Column (" + row_count + ", 2)");
    row.Cells.Add("Column (" + row_count + ", 3)");
}

// Add table object to the first page of the input document
doc.Pages[1].Paragraphs.Add(table);

// Save the updated document containing the table object
doc.Save("c:/pdftest/TableOutput.pdf");

cshanmugasundaram:
4. how to use same font and size, i am using font, but problem in font repository

You may consider either using HTML text where you can specify font name if you do not want to use FontRepository.

cshanmugasundaram:
5. you see the appendix information, user entered just information without line break, how to achieve this onep

The information entered inside table cell is autowrapped to next lines. All you have to do is to specify certain width for cells representing Appendix and in order to represent Appendix, you can have a separate table.

cshanmugasundaram:
6. how to set background color for appendix information

Please try using following code line row.Cells[0].BackgroundColor = Aspose.Pdf.Color.Gray;

In case you have any further query, please feel free to contact.

Hi, thanks for your reply.


i have extract the table from existing PDF and they have used some different font which is i am not able use it due to not installed in my machine.

how to use this same font which they have used in existing font without installed in my machine, and we are using azure environment to deploy our solution. how to use this?

i am creating table but not like existing one. i can create only 11 column due to space, after that i am getting issue.

but existing PDF they have 13 columns

in column they are using something like TM and 1, how to create that 1?


Hi There,

Thanks for your inquiry. Please note that the font you want to embed while creating the PDF document, must be installed on the host machine.

Moreover, You can adjust the width of table columns according to page size. This way you can have more columns inside a single page.

“in column they are using something like TM and 1, how to create that 1?”

You can use HTML string to specify that formatting into table cell. Please check the following code snippet.

Aspose.Pdf.Document doc = new Aspose.Pdf.Document();
doc.Pages.Add();

// 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));

HtmlFragment titel = new HtmlFragment("CyflufenamidTM&nbsp1");

// 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();
    row.Cells[0].Paragraphs.Add(titel);
    row.Cells[0].BackgroundColor = Aspose.Pdf.Color.Green;

    row.Cells.Add("Column (" + row_count + ", 2)");
    row.Cells.Add("Column (" + row_count + ", 3)");
}

table.ColumnAdjustment = ColumnAdjustment.AutoFitToWindow;

// Add table object to the first page of the input document
doc.Pages[1].Paragraphs.Add(table);

// Save the updated document containing the table object
doc.Save("TableOutput.pdf");

In case of any further assistance please feel free to contact us.

Best Regards,