我有一些PowerShell代码可以将word文档转换为pdf。它工作得很好,但有一个问题。无论出于何种原因,pdf在转换过程中被创建为pdf图像而不是文本..遗憾的是我需要文本。必须有一些参数可以传递来改变它。有没有人遇到过这个?
这是代码
$Path = "SomePath"
$OutPath = "SomePath"
$Ftype = $Path + "*.doc"
$NewSuffix = ".pdf"
## invoke WORD application
##
$word_app = New-Object -ComObject Word.Application
$word_app.visible = $False
##
## Get the files from the folder
##
$files = Get-ChildItem $Ftype
##
## process each file - open in WORD and save as PDF in output folder
## then delete original WORD file
##
write-host "Starting DOC Conversion"
ForEach ($file in $files) {
$d2 = $file.name
$Out = $OutPath + $d2 -replace ".doc", $NewSuffix
#$Out = $Out -replace '\s',''
$LogLine = "Converting from " + $file.fullname + " to " + $Out
$LogLine >>'C:\temp\WordPDF.LOG'
write-host $LogLine
$document = $word_app.Documents.Open($file.fullname)
$document.SaveAs($Out, 17)
$document.Close()
$Dcounter = $Dcounter + 1
$Wcounter = $Wcounter + 1
if ($Deletefiles) {
Remove-Item $file
write-host "Deleting " $file.fullname
}
}
$word_app.Quit()