我有一个文本文件,其中包含简单的固件版本。我需要使用 powershell 脚本将文本文件转换为安全的 pdf 文件。
另外,有没有办法在文件转换时在文件上添加日期和时间戳?
我不太知道该怎么做,我对 powershell 还很陌生,谢谢!
最佳答案
我可以在 Word 2010 中使用它,但它也应该在 2007 中使用:
# File paths
$txtPath = "C:\Users\Public\test.txt"
$pdfPath = "C:\Users\Public\test.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
$selection.typeText($txt)
# Set the page orientation to landscape
$doc.PageSetup.Orientation = 1
# Export the PDF file and close without saving a Word document
$doc.ExportAsFixedFormat($pdfPath,$wdExportFormatPDF)
$doc.close([ref]$wdDoNotSaveChanges)
$word.Quit()
关于.net - 使用 Powershell 将文本文件转换为 PDF 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23892631/