Powershell delete last page in word document and convert to pdf
I have been trying to write a powershell program that does 4 things:
- Opens an existing word document
- Removes the last page (usually page #3)
- Converts the document to pdf
- Saves the converted document using the same name + the text "converted"
I tried writing code myself but I know nothing about powershell. If someone could help me I would greatly appreciate it. My broken code is below.
# Opening word and document
$word = New-Object -comobject Word.Application
$FileName = “C:\Users\mark\Test document.doc”
$word.Visible = $true
$doc = $word.Documents.Open($FileName)
#Print ref
$Missing = [System.Reflection.Missing]::Value # Default values
$BackGround = 0
$Append = 0
$Range = 4
$OutputFileName = $FileName + "converted"
$From = $Missing
$To = $Missing
$Item = 0
$Copies = 1 # Number of copies
$Pages = "1-2" # Page range
$Word.printout([ref]$BackG开发者_JAVA百科round, [ref]$Append, [ref]$Range, [ref]$OutputFileName, [ref]$From, [ref]$To, [ref]$Item, [ref]$Copies, [ref]$Pages)
# Closing Document and Word
$doc.Close()
精彩评论