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
page.Graphics.Save();
//Set scaling factor
page.Graphics.ScaleTransform(scale,1);
//Draw the string
page.Graphics.DrawString(text, font, PdfBrushes.Black, PointF.Empty);
//Restore the graphics
page.Graphics.Restore();
//Save the PDF document
doc.Save("output.pdf");
//Close the document
doc.Close(true);
|
Please let us know if you have any concern.
Regards,
Chinnu