PowerShell から PDF を作成するスクリプトに取り組んでいます。ComObjectを使用して、Wordを使用して動作させています。しかし、それは私がそれを実行するコンピューターに Word が必要であることを意味します。多分メモ帳からPDFファイルを作る方法があれば、私はさまよっていました。これは、Word から PDF を作成したコードです。
<`#make pdf
# Required Word Variables
$wdExportFormatPDF = 17
$wdDoNotSaveChanges = 0
# Create a hidden Word window
$word = New-Object -ComObject word.application
$word.visible = $false
# Add a Word document
$doc = $word.documents.add()
# Put the text into the Word document
$txt = Get-Content $txtPath
$selection = $word.selection
foreach($line in $txt){
$selection.typeText($line) | Format-wide
$selection.typeparagraph()
}
# Export the PDF file and close without saving a Word document
$doc.ExportAsFixedFormat($pdfPath,$wdExportFormatPDF)
if($?){write-host 'Users and Groups saved to ' $pdfPath -ForegroundColor Cyan}
$doc.close([ref]$wdDoNotSaveChanges)
$word.Quit()`>