How to apply a cellstyle to a specific column on a PdfGrid

Hello good day, I'm using Syncfusion for the first time, so I could manage to draw a pdfGrid and i could give a style to a row, but i haven't been able to give a style to a column, in the image that i attached you'll see all the grid is align to the right but i need to align the first two columns to the left. Any ideas?Captura de pantalla 2025-07-13 080248.jpg


1 Reply

IJ Irfana Jaffer Sadhik Syncfusion Team July 14, 2025 09:56 AM UTC

Hi Federico,

Thanks for reaching out.


To align specific columns in your PdfGrid, you can set the Format API
on individual columns using PdfStringFormat. This allows you to control the text alignment for each column separately.


Please refer to the following snippet code for guidance:


// Create a new PDF document.

PdfDocument document = new PdfDocument();

// Add a page to the document.

PdfPage page = document.Pages.Add();

// Create a PdfGrid.

PdfGrid pdfGrid = new PdfGrid();

 

// Add values to list

List<object> data = new List<object>

{

    new { NOTA = "Q1120", NOMBRE = "FEDE", CANTIDAD = "1081" },

    new { NOTA = "Q1121", NOMBRE = "CIRCULO K", CANTIDAD = "1118" },

    new { NOTA = "Q1120", NOMBRE = "CIRCULO K", CANTIDAD = "249" },

    new { NOTA = "Q1121", NOMBRE = "QUÍMICA VARGAS", CANTIDAD = "1118" },

    new { NOTA = "Q1122", NOMBRE = "QUÍMICA VARGAS", CANTIDAD = "249" },

    new { NOTA = "Q1119", NOMBRE = "BOLT-DIDI", CANTIDAD = "30" },

    new { NOTA = "", NOMBRE = "LIMPIECITO", CANTIDAD = "182" }

};

 

// Assign data source.

pdfGrid.DataSource = data;

 

// Set alignment for the first column (NOTA) to left

pdfGrid.Columns[0].Format = new PdfStringFormat

{

    Alignment = PdfTextAlignment.Left

};

 

// Set alignment for the second column (NOMBRE) to left

pdfGrid.Columns[1].Format = new PdfStringFormat

{

    Alignment = PdfTextAlignment.Left

};

 

// Optionally, align the third column (CANTIDAD) to right

pdfGrid.Columns[2].Format = new PdfStringFormat

{

    Alignment = PdfTextAlignment.Right

};

 

// Draw the grid on the page

pdfGrid.Draw(page, new Syncfusion.Drawing.PointF(0, 0));

 

// Save the document

using (FileStream outputFileStream = new FileStream("Output.pdf", FileMode.Create, FileAccess.Write))

{

    document.Save(outputFileStream);

}

// Close the document

document.Close(true);

 



This will align the first two columns (`NOTA` and `NOMBRE`) to the left, while keeping the third column (`CANTIDAD`) aligned to the right.


Please try this on your end and let us know the feedback.


Regards,

Irfana J


Loader.
Up arrow icon