We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Set line spacing for PdfGraphics.DrawString()

I'm making a call to PdfGraphics.DrawString with a string that has newline characters in it. How can I control the line spacing? I am modifying an existing PDF.

Thanks in advance.

3 Replies

GR Gayathri Ramalingam Syncfusion Team March 30, 2017 11:36 AM UTC

Hi Scott, 
Thank you for using Syncfusion product. 
We can set the line space and newline characters using PdfStringFormat in the existing PDF document. 
Please find the code snippet, 
//Load a PDF document. 
PdfLoadedDocument doc = new PdfLoadedDocument(stream); 
//Get first page from document 
PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage; 
//Create PDF graphics for the page 
PdfGraphics graphics = page.Graphics; 
//Set the standard font. 
PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 20); 
PdfStringFormat drawFormat = new PdfStringFormat(); 
drawFormat.WordWrap = PdfWordWrapType.Word; 
drawFormat.Alignment = PdfTextAlignment.Justify; 
drawFormat.LineAlignment = PdfVerticalAlignment.Top; 
drawFormat.LineSpacing = 20f; 
drawFormat.WordSpacing = 10f;      
 //Draw the text. 
graphics.DrawString("Essential PDF supports various page setting options to control the page display." + Environment.NewLine + "You can choose the standard or custom page size when you add a page to the PDF document. This sample below illustrates how to create a PDF document with standard page size.!!!", font, PdfBrushes.Black, new RectangleF(0, 200, page.Size.Width, page.Size.Height), drawFormat); 
//Save the document. 
Please find the sample form the below link, 
Please let us know if you need further assistance on this. 
With Regards, 
Gayathri R 

SH Scott Hoelsema March 30, 2017 06:36 PM UTC

That helps, thanks.

GR Gayathri Ramalingam Syncfusion Team March 31, 2017 08:55 AM UTC

Hi Scott,  
We are glad that the issue is resolved at your end and please let us know if you need further assistance. We are always glad to assist you.   
With Regards, 
Gayathri R 

Live Chat Icon For mobile
Up arrow icon