.txt font replacement

Hello,

Please can you provide an example of how I can replace a font in a .txt file.

I have tried the following but none seem to work.

LoadOptions GetLoadOptions(LoadContext context)
{
    var loadOptions = new WordProcessingLoadOptions
    {
        Password = decryptedPassword,
        Format = (WordProcessingFileType)FileType.FromExtension(Path.GetExtension(fileToConvert.FileName)),
    };

    var fontReplacement = FontSubstitute.Create("Courier New", "Comic Sans MS");
    loadOptions.FontSubstitutes.Add(fontReplacement);
    loadOptions.FontNameSubstitutionEnabled = true;
    loadOptions.DefaultFont = "Comic Sans MS";

    return loadOptions;
}

Then the load options are used as follows:

using var converter = new Converter(() => ms, (lc) => GetLoadOptions(lc));

Thanks

I am aware that the .txt format does not store any font information.

I have tried setting the DefaultFont property on the LoadOptions but this did not work as expected.

Also, none of the help articles linked by the AI bot work. They both 404.

Forgot to mention in the original ticket, the output type is PDF.

Hello @rthomas95 ,

Thank you for reaching out to us. As our AI bot mentioned above, a .txt file by itself cannot contain different fonts. It is the simplest format: it only stores characters (letters, numbers, spaces, etc.) in a certain encoding (UTF-8, ANSI, etc.). Information about font size, color, style (bold, italic), and so on is not stored in the file.
The font is chosen by the program that opens the file (for example, Notepad, VS Code, or WordPad). However, I would like to point out that from your question it is not entirely clear whether you want to convert the .txt file into another format, such as .docx or .pdf, since you only provided code for loading the document. We are not sure what exactly you would like to achieve as a result of the conversion.

Hello,

Thank you for your response, yes apologies for missing that out.

I am converting the .txt file to PDF.

It is my assumption that the DefaultFont property of the WordProcessingLoadOptions should handle this, because as we know the text file format does not store any font information.

Thanks

@rthomas95 ,

Unfortunately, neither the FontSubstitutes property nor DefaultFont can help you apply the desired font when converting a .txt file to .pdf, since this functionality is not currently supported in this use case of GroupDocs.Conversion. This is because such properties can only be applied to documents that contain font information.
However, we found your scenario of using GroupDocs.Conversion interesting, and our developers would like to investigate it further and attempt to implement it in future versions. Do you have any additional comments or suggestions for this potential functionality, or would you be satisfied simply with the ability to set the required font in the resulting .pdf document?

Thanks for confirming. If this isn’t too difficult to add it would be greatly appreciated, however I appreciate this use case is quite niche.

I run a bunch of command line tools that create a text files which I then merge together using Powershell and want to convert to PDF.

I also can’t think of any other suggestions for such a feature, as by the nature of the text file format, it is incredibly limited.

@rthomas95 ,

Thank you for clarifying your use case. As I mentioned earlier, our developers are investigating the possibility of implementing this functionality, and I will inform you as soon as I have any updates. We always strive to listen to our customers, so if you have any further product suggestions in the future, please do not hesitate to share them with us.