我试图创建一个PowerShell脚本来打印文档的某个页面,我知道打印整个文件的命令如下
start-process -FilePath $file.fullName -Verb Print
但我只想要打印文档的倒数第二页 感谢
答案 0 :(得分:0)
如果你知道相关的页面没有使用Application.PrintOut方法,那么如果它的单词doc很困难但并非不可能。您需要将打印输出字段填充到页面,如图所示。
# Open Word Document
$FileName = "$env:USERPROFILE\Documents\Example.docx"
$Word = New-Object -comobject Word.Application
$Word.Visible = $true # Use $false to not show document
$word.Documents.Open($FileName)
#Print required Page
$Missing = [System.Reflection.Missing]::Value # use default parameter values
$BackGround = 1
$Append = 1
$Range = $Word.ActiveWindow.Panes(1).Pages.Count # Number of pages in range
$OutputFileName = $Missing
$From = $Missing
$To = $Missing
$Item = 0
$Copies = 1 # Number of Print Copies
$Penultimate = $Range-1
$Pages = "$Penultimate" # Print penultimate page only
$Word.printout([ref]$BackGround, [ref]$Append, [ref]$Range, [ref]$OutputFileName, [ref]$From, [ref]$To, [ref]$Item, [ref]$Copies, [ref]$Pages)
# Close Word
$Word.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($WordDoc)