BoldSignA modern eSignature application with affordable pricing. Sign up today for unlimited document usage!
I'm pulling data from an SQL database with my C# code into variables and formatting the data into a resume that is generated as a PDF once the user clicks a button at the bottom of the webpage. Is it possible to align text to the left and right of the page as necessary without having to specify coordinates? This would make the design process exponentially easier, as the data users input will be of varying lengths and sizes.
Thank you in advance!
The Essential PDF allows you to draw the right-to-left language text in a PDF document. To draw RTL scripts such as Arabic, Hebrew, Persian, and Urdu, set the value of the TextDirection property in the PdfStringFormat class to RightToLeft using PdfTextDirection Enum. The languages (e.g., Sindhi and Kurdish) have more than one script and can be written in either right-to-left or left-to-right format. The LeftToRight value of the TextDirection property is used to draw RTL text in the left-to-right format. Refer to the following code sample:
//Create a new PDF document PdfDocument doc = new PdfDocument(); //Add a page to the document PdfPage page = doc.Pages.Add(); //Create PDF graphics for the page PdfGraphics graphics = page.Graphics; //Create a new PDF font instance PdfFont font = new PdfTrueTypeFont(new Font("Arial", 14), true); //Set the format for string PdfStringFormat format = new PdfStringFormat(); //Set right-to-left text direction for RTL text format.TextDirection = PdfTextDirection.RightToLeft; //Set the text alignment format.Alignment = PdfTextAlignment.Right; format.ParagraphIndent = 35f; //Read the text from file StreamReader reader = new StreamReader("Arabic.txt", Encoding.Unicode); string text = reader.ReadToEnd(); reader.Close(); //Draw string with right-to-left format graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(0, 0, page.GetClientSize().Width, page.GetClientSize().Height), format); //Set left-to-right text direction for RTL text format.TextDirection = PdfTextDirection.LeftToRight; //Set the text alignment format.Alignment = PdfTextAlignment.Left; //Draw string with left-to-right format graphics.DrawString(text, font, PdfBrushes.Black, new RectangleF(0, 100, page.GetClientSize().Width, page.GetClientSize().Height), format); //Save the document doc.Save("Output.pdf"); //Close the document doc.Close(true); |
If still you are facing an issue, we request you to share the additional details about your requirement/ simple sample to demonstrate the issue you are facing in your end. so that we can assist with you further in this