Print all system fonts to Word doc

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Malcolm J Malcolm J 2 weeks ago.

  • Author
    Posts
  • #64678
    Profile photo of Malcolm J
    Malcolm J
    Participant

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

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

    Thanks Malcolm J

  • #64783
    Profile photo of Don Jones
    Don Jones
    Keymaster

    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
      Profile photo of Malcolm J
      Malcolm J
      Participant

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

      Thamks

      Malcolm J.

  • #66222
    Profile photo of Graham Beer
    Graham Beer
    Participant

    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
    Profile photo of Ron
    Ron
    Participant

    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"
      $f=$p.Range.End
      $p.Range.InsertAfter("ABCDEFGabcdefg")
      $t=$p.Range.End
      $p.Range.InsertParagraphAfter()
      $document.Range([ref]($f-1),[ref]$t).Font.Name = $sorted[$i]
    }
    • #66291
      Profile photo of Malcolm J
      Malcolm J
      Participant

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

You must be logged in to reply to this topic.