Hi Ondrej,
Hi,
Hi Ondra,
Thanks for sharing the details.
I am afraid the requested feature is currently not supported. For the sake of correction, I have logged it in our issue tracking system as PDFNEWNET-36819 under the new features list. We will investigate this issue in detail and will keep you updated on the status of a correction.
We apologize for your inconvenience.
Hi Ondra,
Thanks for your patience.
We have further investigated the earlier reported issue and we suggest using a new generator because there is no need for properties like TruetypeFontFileName
and no need to “know the font file name”. Furthermore, if you need to use a special font from a non-system folder, you may consider using any of the overloaded methods FontRepository.OpenFont()
and specify the desired font name. Also, if you do not know the font file name and know the font name, you can use this font name to find the necessary font with the help of FontRepository.FindFont()
. Nevertheless, first, you need to point to the folder containing custom fonts. This can be done using the following code snippet:
FolderFontSource fs = new FolderFontSource(myDir);
FontRepository.Sources.Add(fs);
Aspose.Pdf.Text.Font font = FontRepository.FindFont(desiredFontName);
this will return the desired font from a non-system directory. If the name of a custom font conflicts with the name of some font in the system directory, in such cases, it is necessary only to use a custom directory for the FontRepository
class. This can be done with the following code:
FontRepository.Sources.Clear();
FolderFontSource fs = new FolderFontSource(myDir);
FontRepository.Sources.Add(fs);
Therefore, we need to fonts from different places to system directory and custom directories, in order to avoid conflicts with the same font names, can be achieved by means of the property FontRepository.Sources
(FontSourceCollection object). Just be clear and add necessary folders into this collection appropriately.
The following example specified below creates a new PDF file with text from 2 files: Sample.txt
- text from this file must use the font Frutiger-Normal
from a custom folder, VerdanaText.txt
- text from this file must use the font Verdana
from the system folder.
[C#]
Document doc = new Document();
Page page = doc.Pages.Add();
TextFragment text = ReadText(myDir + "Sample.txt");
//Disconnect
//system font directory to exclude conflicts with a system font Frutiger if it
//exists
FontRepository.Sources.Clear();
//Connect
//custom font directory
FolderFontSource fs = new FolderFontSource(myDir + @"\Fonts");
FontRepository.Sources.Add(fs);
text.TextState.Font = FontRepository.FindFont("Frutiger-Normal");
text.TextState.FontSize = 14;
page.Paragraphs.Add(text);
text = ReadText(myDir + "VerdanaText.txt");
//Here
//we must use the system font Verdana, so to avoid font name conflicts we connect only
//system directory to FontRepository.Sources
FontRepository.Sources.Clear();
SystemFontSource systemSource = new SystemFontSource();
FontRepository.Sources.Add(systemSource);
text.TextState.Font = FontRepository.FindFont("Verdana");
text.TextState.FontSize = 14;
page.Paragraphs.Add(text);
doc.Save(myDir + "out.pdf");
private TextFragment ReadText(string fileName)
{
TextFragment text;
TextReader tr = new StreamReader(fileName);
using (tr)
{
text = new TextFragment(tr.ReadToEnd());
}
return text;
}