Print all system fonts to Word doc

Hi all,
Some time ago, someone assited me in printing all system fonts to a Word document :-
Set-Location C:\Windows\Fonts
$word = New-Object -ComObject “Word.Application”
$word.Visible = $true
$document = $word.Documents.Add()
foreach ($name in $word.FontNames )
$p = $document.Paragraphs.Add();
$p.Range.Text = $name
$p.Range.Font.Name = $name

It worked OK then, but now only prints the first 25 fonts and stops.
Any ideas why?

Thanks Malcolm J

None whatsoever. That COM object is positively ancient. Possibly it’s just tired? Or there could be a font it’s getting stuck on.

Hi Don, don’t understand “That COM object is positively ancient”
could you explain please.


Malcolm J.

COM Objects were introduced by Microsoft back in 1993. I believe what Don is say is that is an older “technology” that was made for Operating systems 24 years ago, so it might not work as it was intended back in 1993.
I’m not aware of another way to connect to Office products like Word other than a COM Object.

It appears that when you use a font from the collection, it changes the position of the font in the list. I only got 5 when I ran it. So, you need to create a static list and loop through it. This worked for me with a fixed label font for the oddball fonts.

$word = New-Object -ComObject "Word.Application"
$word.Visible = $true
$document = $word.Documents.Add()
$sorted = $word.FontNames | sort
for ($i=0;$i -lt $word.FontNames.Count;$i++ ) {
  $p = $document.Paragraphs.Add()
  $p.Range.Text = $sorted[$i] + " ($i) - "
  $p.Range.Font.Name = "Arial"
  $document.Range([ref]($f-1),[ref]$t).Font.Name = $sorted[$i]

Hi Don,
Works a treat! Many thanks
Malcolm J.