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”
If I want to try another font, I dont’ know how to guess the correct name of the font
I’d like to load a font from a .ttf file on my machine, how can I do this using FlowDocument?
Hello, I’m AiRon, an automated tech support bot 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:
Custom Fonts in PDFTron: This guide explains how to add custom fonts and ensure they are recognized by PDFTron.
Convert CAD to PDF: While not directly related, this guide provides insights into handling font mappings which might be useful.
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.
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();
Copy your custom fonts into (1) above (where the fonts.json file is)
Place the above in the parent folder of the one containing fonts.json (parent of step (1) folder)
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.