Print all system fonts to Word doc

This topic contains 5 replies, has 4 voices, and was last updated by  Malcolm J 1 year, 4 months ago.

  • Author
  • #64678

    Malcolm J

    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

  • #64783

    Don Jones

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

    • #66133

      Malcolm J

      Hi Don, don't understand "That COM object is positively ancient"
      could you explain please.


      Malcolm J.

  • #66222

    Graham Beer

    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.

  • #66285


    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]
    • #66291

      Malcolm J

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

You must be logged in to reply to this topic.