Skip to content

Instantly share code, notes, and snippets.

@xcud
Created February 7, 2013 21:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcud/4734508 to your computer and use it in GitHub Desktop.
Save xcud/4734508 to your computer and use it in GitHub Desktop.
Writes a string to a PDF via Microsoft Word automation
<#
.Synopsis
Writes a string to a PDF via Microsoft Word automation
.Example
PS> ps | out-string | out-pdf -Path ".\processes.pdf"
#>
function Out-PDF() {
param(
[Parameter(Mandatory=$True, Position=0, ValueFromPipeline=$true)] $Text,
[Parameter(Mandatory=$True, Position=1)] $Path
)
$word=new-object -ComObject "Word.Application"
$doc=$word.documents.Add()
$selection=$word.Selection
$selection.TypeText($Text)
$doc.SaveAs([ref]([io.path]::GetFullPath($Path)), [ref]17)
$doc.Close([ref]$false)
$word.quit()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment