开发者

Powershell delete last page in word document and convert to pdf

I have been trying to write a powershell program that does 4 things:

  1. Opens an existing word document
  2. Removes the last page (usually page #3)
  3. Converts the document to pdf
  4. 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()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜