I'm trying to tell PowerShell to open a text file and choose a certain encoding option. By default, when opening this text file in Word manually, it tries to open it with Japanese encoding and so doesn't show certain characters correctly.
I've tried lots of different things but nothing works so I'm totally stuck.
This text file, amongst others, needs to be converted to PDF on a daily basis.
My current script is as follows:
$wdFormatPDF = 17
$word = New-Object -ComObject Word.Application
$word.Visible = $true
$folderpath = "C:\Users\smirabile\Downloads\report-testing-destination\*"
$fileTypes = "accepted.spl"
Get-ChildItem -Path $folderpath -Include $fileTypes | ForEach-Object {
$path = ($_.FullName).Substring(0, ($_.FullName).LastIndexOf("."))
$doc = $word.Documents.Open($_.FullName)
$Word.Selection.PageSetup.Orientation = 1
$Word.Selection.PageSetup.LeftMargin = 20
$Word.Selection.PageSetup.RightMargin = 20
$doc.Select()
$Word.Selection.Font.Size = 9
$doc.SaveAs([ref]$path, [ref]$wdFormatPDF)
$doc.Close()
}
$word.Quit()
Stop-Process -Name WINWORD -Force