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. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Set line spacing for PdfGraphics.DrawString()

Thread ID:





129712 Mar 29,2017 08:36 PM UTC Mar 31,2017 08:55 AM UTC ASP.NET Web Forms 3
Tags: PDF
Scott Hoelsema
Asked On March 29, 2017 08:36 PM UTC

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.

Gayathri Ramalingam [Syncfusion]
Replied On 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 

Scott Hoelsema
Replied On March 30, 2017 06:36 PM UTC

That helps, thanks.

Gayathri Ramalingam [Syncfusion]
Replied On 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 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon