首页 > 解决方案 > Adding Open Type Fonts to a Private Font Collection using Add Font File method

问题描述

This is my first question here on stack overflow. I hope someone can help me. I need to add a large collection of Open Type Fonts to a private font collection object so I can extract the font name from each of the otf files. This will allow me to check if the font is already installed on a target system. Instead of checking the file names which is not reliable.

Here is my code:

Add-Type -AssemblyName System.Drawing
$path = "\\Themis\Fonts\*.*"
$otffiles = Get-ChildItem $path
$fontCollection = New-Object System.Drawing.Text.PrivateFontCollection
$otffiles | ForEach-Object{
$fontCollection.AddFontFile($_.fullname)
}
$fontcollection.Families

The above code works perfectly on Windows 10. However if I run this same exact code on Windows 7 I receive a "File Not Found" exception which I understand is thrown when the font file is not supported. I cannot believe that Windows 10 supports this method of dealing with otf files and Windows 7 doesn't. Am I missing something? Is there another way to skin this cat?

Thanks in advance

标签: powershellfonts

解决方案


推荐阅读