我正在编写一个脚本来从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()`>