【问题标题】:Powershell script to print certain pages of a file用于打印文件某些页面的 Powershell 脚本
【发布时间】:2019-07-04 22:59:23
【问题描述】:

我正在尝试创建一个 powershell 脚本来打印文档的某个页面,我知道打印整个文件的命令如下

start-process -FilePath $file.fullName -Verb Print

但我只想打印文档的倒数第二页 谢谢

【问题讨论】:

  • 我相信您需要使用一个为此公开某种接口的程序。例如 MS Word。
  • 你如何决定页面在哪里停止和开始?

标签: powershell


【解决方案1】:

如果您知道使用 Application.PrintOut 方法的相关页码,如果它是一个单词文档,那么它是困难的,但并非不可能。您确实需要将打印输出字段填充到所示的页面。

# 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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-28
    • 2023-03-23
    • 1970-01-01
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    相关资源
    最近更新 更多