View and Convert PSD with Custom Fonts
Contents
[
Hide
]
View and Convert PSD with custom fonts in C#
GroupDocs.Viewer for .NET (which is a part of Conholdate.Total for .NET) provides facility to view and convert PSD with custom fonts. You can set the default font when you rendering PSD file format.
How to set directories for fonts
To specify directories with your custom fonts, follow the below steps:
- Instantiate the FolderFontSource object - set folder path, and SearchOption - AllFolders - to search for fonts recursively, TopFolderOnly - to search for fonts only in the current folder;
- Call SetFontSources method of FontsSettings class.
FolderFontSource folderFontSource = new FolderFontSource(@"C:\custom_fonts_folder", SearchOption.TopFolderOnly);
FontSettings.SetFontSources(folderFontSource);
Your fonts will be loaded before open your document.
Convert PSD with custom fonts
To convert PSD files with custom fonts with GroupDocs.Viewer for .NET follow the below steps:
- Instantiate the FolderFontSource object - set folder path, and SearchOption - AllFolders - to search for fonts recursively, TopFolderOnly - to search for fonts only in the current folder;
- Call SetFontSources method of FontsSettings class and supply font sources as arguments.
- Instantiate the Viewer object;
- Instantiate HtmlViewOptions (or JpgViewOptions, or PngViewOptions, or PdfViewOptions) object;
- Set DefaultFontName property in options - set your font name;
- Call View method.
- The following code sample shows how to set the output image size limits when rendering the document.
// Create font sources.
// Add custom fonts folder to look for fonts recursively. (look into subfolders too).
FolderFontSource folderFontSource = new FolderFontSource(@"C:\custom_fonts_folder", SearchOption.AllFolders);
// Add custom fonts folder to look for fonts only in this folder (wihout subfolders).
FolderFontSource additionalFontSource = new FolderFontSource(@"C:\custom_additional_fonts_folder", SearchOption.TopFolderOnly);
// Call SetFontSources method and supply font sources as arguments.
FontSettings.SetFontSources(folderFontSource, additionalFontSource);
using (Viewer viewer = new Viewer("sample.psd"))
{
JpgViewOptions options = new JpgViewOptions("result.jpg");
options.DefaultFontName = "Arial";
viewer.View(options);
}