How to set the CharacterSpacing and WordSpacing when inserting text to pdf

I’d like to set the CharacterSpacing and WordSpacing when inserting text into pdf.

The PDFFormattedText looks good to insert text into pdf, but I do not see how to set the CharacterSpacing and WordSpacing.

Is there a way to do that?

Thanks

Hi Jason,

Try this:

using (var document = new PdfDocument())
{
    var page = document.Pages.Add();

    using (var formattedText = new PdfFormattedText())
    {
        formattedText.FontFamily = new PdfFontFamily("Times New Roman");
        formattedText.FontSize = 24;
        formattedText.AppendLine("Hello World");
        page.Content.DrawText(formattedText, new PdfPoint(100, 600));
    }

    document.Save("without-spacing.pdf");

    var textElement = page.Content.Elements.All().OfType<PdfTextContent>().First();
    textElement.Format.Text.CharacterSpacing = 5;
    textElement.Format.Text.WordSpacing = 20;

    document.Save("with-spacing.pdf");
}

Does this solve your issue?

Regards,
Mario