Hi Syncfusion team,
Is the RTL direction possible with PdfGrid?
I.e, when direction = RTL, the first column will be displayed at the right and so on.
Else, how to change the direction?
Best regards
Hi Cosyspro,
To set the RTL direction in a `PdfGrid`, you can use `PdfStringFormat` to ensure the text is aligned correctly for RTL languages. Below is a refined solution for creating an RTL `PdfGrid` using Syncfusion:
using Syncfusion.Pdf; using Syncfusion.Pdf.Graphics; using Syncfusion.Pdf.Grid; using System.Drawing; using System.IO; public class PdfCreator { public void CreateRtlPdf() { // Create a new PDF document using (PdfDocument document = new PdfDocument()) { // Add a page PdfPage page = document.Pages.Add(); PdfGraphics graphics = page.Graphics; // Create a new PdfGrid PdfGrid pdfGrid = new PdfGrid(); // Add columns to the grid pdfGrid.Columns.Add(3); // Add rows to the grid PdfGridRow header = pdfGrid.Headers.Add(1)[0]; header.Cells[2].Value = "Header 1"; header.Cells[1].Value = "Header 2"; header.Cells[0].Value = "Header 3"; // Adding rows to grid as per RTL order PdfGridRow row1 = pdfGrid.Rows.Add(); row1.Cells[2].Value = "Row 1 - Cell 1"; row1.Cells[1].Value = "Row 1 - Cell 2"; row1.Cells[0].Value = "Row 1 - Cell 3"; PdfGridRow row2 = pdfGrid.Rows.Add(); row2.Cells[2].Value = "Row 2 - Cell 1"; row2.Cells[1].Value = "Row 2 - Cell 2"; row2.Cells[0].Value = "Row 2 - Cell 3"; // Set the format for RTL language PdfStringFormat format = new PdfStringFormat(); format.Alignment = PdfTextAlignment.Right; format.TextDirection = PdfTextDirection.RightToLeft; // Apply string formatting for the whole table for (int i = 0; i < pdfGrid.Columns.Count; i++) { pdfGrid.Columns[i].Format = format; } // Draw the grid to the page pdfGrid.Draw(graphics, new PointF(0, 0)); // Stream the document to disk using (FileStream stream = new FileStream("RtlPdfGrid.pdf", FileMode.Create, FileAccess.Write)) { document.Save(stream); } } } } |
This code snippet ensures that your columns and text align according to RTL conventions. Please try this on your end and let us know the result. If you are still facing an issue, please share with us the modified sample with us, so that we can assist with you further in this.
Regards,
Irfana J.
Hi Irfana,
Thank you for your help.
This is what I am currently using.
I just wanted to know if the RTL function can be applied directly to PdfGrid.
Best reg
Hi Cosyspro,
In Syncfusion's PDF library, Right-to-Left (RTL) text is typically not directly supported at the `PdfGrid` level as a whole. However, you can achieve RTL text alignment by setting the string format of individual cells within the `PdfGrid`. This requires specifying a `PdfStringFormat` with the alignment set to right.
This method provides a flexible way to align text within a grid, accommodating both RTL and LTR languages at the cell level rather than the grid level.
Regards,
Irfana J.