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

Adjusting Font Width Only

Thread ID:





132014 Aug 8,2017 03:05 PM UTC Aug 9,2017 12:30 PM UTC WinForms 1
Tags: PDF
James Riddles
Asked On August 8, 2017 05:29 PM UTC

I am working on a project to place text on a line in a PDF.  The line will have a max width of a variable amount.  I have successfully written a function to repeatedly reduce the size of the font by 0.5 points at a time, until the text fits.  Is there any way that I can affect the horizontal scaling only?  Or, perhaps the character spacing, as well?


Chinnu Muniyappan [Syncfusion]
Replied On August 9, 2017 12:30 PM UTC

Hi James, 
Thank you for contacting Syncfusion support. 
The font size reducing workaround is the right way to fit the text with in smaller bounds. And we can scale the text horizontally/vertically by using PdfGraphics.ScaleTransform. If horizontal scaling is applied to a string then the whole string will shrink compared to its regular size. we have created a simple sample for your reference, please refer the below code snippet and sample for more details. 
            //Create a new PDF document 
            PdfDocument doc = new PdfDocument(); 
            //Add a new page 
            PdfPage page = doc.Pages.Add(); 
            //input text 
            string text = "Hello World!."; 
            //Create new PDF font 
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12, PdfFontStyle.Regular); 
            //Measure the text width. 
            float textWidth = font.MeasureString(text).Width; 
            //Represent the line width to fix the text. 
            float lineWidth = 30; 
            //Find scaling factor 
            float scale = lineWidth / textWidth; 
            //Save the graphics 
            //Set scaling factor 
            //Draw the string 
            page.Graphics.DrawString(text, font, PdfBrushes.Black, PointF.Empty); 
            //Restore the graphics 
            //Save the PDF document 
            //Close the document 
Please let us know if you have any concern. 


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