How to set Text alignment for a specific PDFGrid''s cell?

Hi!

I try to center the Text with the code below; however it does not work.

PdfGrid grid = new PdfGrid();
grid.Columns.Add(3);

PdfGridRow row;



row.Cells[1].Style.Font = new PdfStandardFont(PdfFontFamily.Courier, 20, PdfFontStyle.Bold);

row.Cells[1].Style.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

row.Cells[1].Value = ("CENTER TEXT");


How do I center a text in a specific cell?

Thanks!


5 Replies

PJ Priyadharshini J Syncfusion Team November 16, 2010 05:34 AM UTC

Hi Kim,

Thank you for your interest in Syncfusion proudcts.

We have placed a sample in the link below to align the text to the center of a specific cell.

forum-785344585.zip


Kindly try this and let us know if you have any queries.

Regards,
Priyadharshini




KI kim November 16, 2010 04:04 PM UTC

Hi Priyadharshini!

Thanks, for quick response!

Followed your example, I just changed the code below:

row.Cells[1].Style.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

TO:

row.Cells[1].StringFormat.Alignment = PdfTextAlignment.Center;

and it is working.

Thanks!



SP Selvakumar P Syncfusion Team November 17, 2010 11:29 AM UTC

Hi Kim,

Thank you for your response.we are glad hear that it is working good.

Regards,
Selvakumar.






MR Mohd Rushdan replied to kim April 26, 2019 03:42 AM UTC

Hi Priyadharshini!

Thanks, for quick response!

Followed your example, I just changed the code below:

row.Cells[1].Style.StringFormat = new PdfStringFormat(PdfTextAlignment.Center);

TO:

row.Cells[1].StringFormat.Alignment = PdfTextAlignment.Center;

and it is working.

Thanks!


Hi How to center all column without assign the index ?

Thank you.


SL Sowmiya Loganathan Syncfusion Team April 29, 2019 10:29 AM UTC

Hi Mohd, 

At present we cannot center all column wihtout assigning the index. However we can align individual column to center using the below code snippet, 

//Create and customize the string formats 
PdfStringFormat format = new PdfStringFormat(); 
format.Alignment = PdfTextAlignment.Center; 
//Set the column text format  
pdfGrid.Columns[0].Format = format; 

Align centre to all column by providing index: 

//Create and customize the string formats 
PdfStringFormat format = new PdfStringFormat(); 
format.Alignment = PdfTextAlignment.Center; 
for (int i = 0; i < pdfGrid.Columns.Count; i++) 
{ 
    //Set the column text format  
    pdfGrid.Columns[i].Format = format; 
} 

Please refer the below UG documentation link for more details, 

Please let us know if you need any further assistance on this. 

Regards, 
Sowmiya L 


Loader.
Up arrow icon