Exporting Justified Paragraph on RTF to PDF resulting wrong spacing in the PDF

1 Answer 12 Views
PdfProcessing WordsProcessing
Mozart
Top achievements
Rank 1
Iron
Veteran
Mozart asked on 07 Nov 2025, 09:09 AM

Hello,

I want to ask how can make the exported PDF from RTF follows spacing on RTF.
I have RTF file (as attached) , when i try tp export to pdf some paragraph not looking exactly like the RTF , i suspect it because using Justified setting.
Is it a bug ? or can we export the RTF to PDF that have exacts look after exporting to PDF ?

i use Telerik.Documents.Core, Fixed, Flow, Flow.FormattedProvider.Pdf , File Version : 2025.2.520.20 
The project is a .NET 8 class library

Please see attached file (RTF source and exported PDF).

private bool ConvertRtfToPdfWithTelerik(string rtfPath, string pdfPath)
{
    try
    {
        Console.WriteLine("Converting RTF to PDF using Telerik Document Processing...");

        // Create RTF format provider
        RtfFormatProvider rtfProvider = new RtfFormatProvider();

        Telerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider();
        Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider;
        
        // Load RTF document
        RadFlowDocument document;
        //Size oSize = new Size();
        //Padding oPadding = null;

        using (FileStream rtfStream = new FileStream(rtfPath, FileMode.Open))
        {
            document = rtfProvider.Import(rtfStream, null);
            //oSize = document.Sections[0].PageSize;
            //oPadding = document.Sections[0].PageMargins;
        }

        //foreach (var item in document.Sections)
        //{
        //    //item.PageMargins = new Padding(90);
        //    item.PageSize = PaperTypeConverter.ToSize(PaperTypes.Letter);
        //}

        Console.WriteLine("RTF document loaded successfully with Telerik");

        // Create PDF format provider
        PdfFormatProvider pdfProvider = new PdfFormatProvider();

        // Export to PDF
        using (FileStream pdfStream = new FileStream(pdfPath, FileMode.Create))
        {
            pdfProvider.ExportSettings.FontEmbeddingType = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.FontEmbeddingType.Full;
            pdfProvider.ExportSettings.ImageQuality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.High;
            pdfProvider.Export(document, pdfStream, null);
        }

        Console.WriteLine("PDF generated successfully using Telerik Document Processing");
        return true;
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error converting RTF to PDF with Telerik: " + ex.Message);
        return false;
    }
}

public class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase
{
    public override byte[] GetFontData(Telerik.Windows.Documents.Core.Fonts.FontProperties fontProperties)
    {
        string fontFileName = fontProperties.FontFamilyName + ".ttf";
        string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);

        //The fonts can differ depending on the file 
        if (fontProperties.FontFamilyName == "Calibri")
        {
            if (fontProperties.FontStyle == FontStyles.Italic && fontProperties.FontWeight == FontWeights.Bold)
            {
                fontFileName = $"calibriz.ttf";
            }
            else if (fontProperties.FontStyle == FontStyles.Italic)
            {
                fontFileName = $"calibrii.ttf";
            }
            else if (fontProperties.FontWeight == FontWeights.Normal)
            {
                fontFileName = "calibri.ttf";
            }
            else if (fontProperties.FontWeight == FontWeights.Bold)
            {
                fontFileName = $"calibrib.ttf";
            }
        }

        else if (fontProperties.FontFamilyName == "Century Gothic")
        {
            if (fontProperties.FontStyle == FontStyles.Italic && fontProperties.FontWeight == FontWeights.Bold)
            {
                fontFileName = $"gothicbi.ttf";
            }
            else if (fontProperties.FontStyle == FontStyles.Italic)
            {
                fontFileName = $"gothici.ttf";
            }
            else if (fontProperties.FontWeight == FontWeights.Normal)
            {
                fontFileName = "gothic.ttf";
            }
            else if (fontProperties.FontWeight == FontWeights.Bold)
            {
                fontFileName = $"gothicb.ttf";
            }
        }

        else if (fontProperties.FontFamilyName == "Wingdings")
        {
            if (fontProperties.FontWeight == FontWeights.Normal)
            {
                fontFileName = $"wingding.ttf";
            }
        }

        //...add more fonts if needed... 

        DirectoryInfo directory = new DirectoryInfo(fontFolder);
        FileInfo[] fontFiles = directory.GetFiles();

        var fontFile = fontFiles.FirstOrDefault(f => f.Name.Equals(fontFileName, StringComparison.InvariantCultureIgnoreCase));
        if (fontFile != null)
        {
            var targetPath = fontFile.FullName;
            using (FileStream fileStream = File.OpenRead(targetPath))
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    fileStream.CopyTo(memoryStream);
                    return memoryStream.ToArray();
                }
            }
        }

        return null;
    }
}


1 Answer, 1 is accepted

Sort by
0
Accepted
Yoan
Telerik team
answered on 11 Nov 2025, 02:04 PM

Hello Mozart,

Thank you for reaching out and for the provided resources.

I tested the document on my end and exported it to PDF. Correct me if I am wrong, but from what I understand, you are talking about the following differences after the PDF export:

This issue seems to be caused by the applied "First line" indent to the rows, however, this behavior appears to have been fixed down the line. In our most recent Document Processing version (2025.3.1007), this issue does not reproduce, and the rows are correctly aligned. If you haven't already, I suggest updating the version on your end and seeing if this changes anything.

The only thing that is still not preserved during the PDF conversion (even with our latest version) is the character spacing. In this case, that means that the characters in the exported PDF will be closer to each other (default value) than in the RTF document (where they have a larger space in between). We already have a logged task in our Feedback Portal regarding the implementation of this feature - WordsProcessing: Add character spacing support. If you are interested in this task, please know that you can cast your vote for it in order to increase its priority in our backlog and to subscribe so you can track its progress and receive notifications about potential status updates in the future.

This is what the PDF export looks like with our latest Document Processing 2025.3.1007 version:

I hope this helps.

Regards,
Yoan
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
PdfProcessing WordsProcessing
Asked by
Mozart
Top achievements
Rank 1
Iron
Veteran
Answers by
Yoan
Telerik team
Share this question
or