Created
February 7, 2013 21:41
-
-
Save xcud/4734508 to your computer and use it in GitHub Desktop.
Writes a string to a PDF via Microsoft Word automation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.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