How to set a font using FlowDocument

Product:PDFTron.NET.x64

Product Version:11.1.0

Please give a brief summary of your issue:
(Think of this as an email subject)
Cannot use my .ttf file while geneating Pdf via FlowDocument

Please describe your issue and provide steps to reproduce it:
(The more descriptive your answer, the faster we are able to help you)
I’ve tried to change the font of the pdf using FlowDocument.AddParagraph().GetTextStyledElement().SetFontFace(“”).
It worked with the string “Microsoft Sans Serif”

  1. If I want to try another font, I dont’ know how to guess the correct name of the font
  2. I’d like to load a font from a .ttf file on my machine, how can I do this using FlowDocument?
1 Like

Hello, I’m AiRon, an automated tech support bot :robot:
While you wait for one of our customer support representatives, I can help you with your question.


To set a font using a .ttf file in a FlowDocument with PDFTron.NET, you need to ensure that the font is properly loaded and available for the document to use. The PDFTron SDK allows you to specify custom fonts for your documents.

Some things you can try:

  • Ensure your .ttf file is accessible by your application, typically by placing it in a known directory.

  • Use the PDFNet.AddResourceSearchPath() method to add the directory containing your .ttf file to the resource search paths.

  • Ensure that the font name you use in SetFontFace() matches the name defined within the .ttf file. You can check this by opening the .ttf file properties on your operating system.

  • After setting up the resource path, use SetFontFace() with the correct name to apply the font to your FlowDocument.



Here are some resources that might help you:


Hopefully, this helps you solve your problem while you wait for a human to get back to you.

1 Like

You can find information for both of your requirements below, please let me know if you have any questions regarding what I have provided here.

For determining available fonts: we don’t provide this in the PDFNet SDK, but you can accomplish this by leveraging the .Net InstalledFontCollection class.

To use custom .ttf font files: you need to create your own custom font package. You can accomplish this with the following instructions.

  1. Download SelfServeWebFonts
    https://pdftron.s3.amazonaws.com/downloads/SelfServeWebFontsV2.zip

  2. Unzip (1) somewhere

  3. Modify your code with the following two lines of code

PDFNet.Initialize(PDFTronLicense.Key); // this line should already exist in your code
WebFontDownloader.SetCustomWebFontURL("file:///usr/share/fonts/WebFontDest/"); // update path to what was used in (2)
WebFontDownloader.EnableDownloads();
  1. Copy your custom fonts into (1) above (where the fonts.json file is)

  2. Download the WebFontCreator tool (native, platform, specific tool here)
    Linux: https://pdftron.s3.amazonaws.com/downloads/linux/WebFontCreator
    Windows: https://pdftron.s3.amazonaws.com/downloads/win/WebFontCreator.exe
    macOS: https://pdftron.s3.amazonaws.com/downloads/mac/WebFontCreator

  3. Place the above in the parent folder of the one containing fonts.json (parent of step (1) folder)

  4. Run the following command.
    ./WebFontCreator --output ./WebFontDest --base ./WebFontDest/fonts.json --fonts ./WebFontDest

Now your self serve fonts folder and fonts.json file are updated to account for your custom fonts.
You should also be able to parse the available font names from the fonts.json file.

Please let us know if you have any additional questions or concerns regarding this at this time.

Daniel House
Apryse Support

1 Like