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.
Unfortunately, activation email could not send to your email. Please try again.

Set line spacing for PdfGraphics.DrawString()

Thread ID:

Created:

Updated:

Platform:

Replies:

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

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 07:36 AM

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. 
doc.Save("Output.pdf"); 
 
 
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 02:36 PM

That helps, thanks.

Gayathri Ramalingam [Syncfusion]
Replied On March 31, 2017 04:55 AM

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 


CONFIRMATION

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.

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.

;