将 Powershell Out-Printer 用于文件时控制输出位置 [英] Control output location when using Powershell Out-Printer to a File

查看:64
本文介绍了将 Powershell Out-Printer 用于文件时控制输出位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Powershell 脚本,它从服务器上的文件夹中检索所有图像文件(.jpg、.png)并将它们打印"到一个文件中,特别是使用特定打印驱动程序的 .prn 文件.所有这些工作正常.问题是我无法弄清楚如何控制打印"输出的位置,即它放置生成的 .prn 文件的位置.他们总是转到我电脑上的图片文件夹.我希望将它们放置在输入图像来自的同一服务器文件夹中.在上周的那一周里,我搜索了我可以尝试尝试的 Powershell 输出、输出文件等的所有组合,但到目前为止还没有找到解决方案.任何帮助,将不胜感激.这是我当前的脚本.

I have a Powershell script that retrieves all image files (.jpg, .png) from a folder on a server and "prints" them to a file, specifically a .prn file using a specific print driver. All of that works fine. The issue is that I can't work out how to control where the output of "printing" goes, i.e. where it puts the resulting .prn file. They always go to the Pictures folder on my PC. I''d like for them to be placed into the same server folder from which the input images came from. Over that last week I've search every combination of Powershell out-print, out-file etc that I can think to try but no luck finding a solution so far. Any help would be appreciated. Here is my current script.

       $VerbosePreference = "Continue"
       add-type -AssemblyName microsoft.VisualBasic
       add-type -AssemblyName System.Windows.Forms
       $newext = ".prn"
       $Directory = "\\192.168.30.46\resource\Item\"
       $files = Get-ChildItem -Path $Directory –File
       $focus = 2000
       for ($i=0; $i -lt 5; $i++) {
       $newfile = $files[$i].BaseName + $newext     
           Start-Process $files[$i].FullName -verb Print | out-printer -name "Page Segment Print File"  
           start-sleep -Milliseconds $focus
           [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 250
           [System.Windows.Forms.SendKeys]::SendWait($newfile)
           start-sleep -Milliseconds 250
           [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 1500
           $focus = 250
       }
       Write-Verbose "Print Files Generated"

推荐答案

创建一个定义的根位置并连接,以便完全定义输出位置.

Create a defined root location and concatenate so the output location is fully defined.

$VerbosePreference = "Continue"
   add-type -AssemblyName microsoft.VisualBasic
   add-type -AssemblyName System.Windows.Forms
   $rootdir = "C:\Temp\"
   $newext = ".prn"
   $Directory = "\\192.168.30.46\resource\Item\"
   $files = Get-ChildItem -Path $Directory –File
   $focus = 2000

   for ($i=0; $i -lt 5; $i++) {
   $newfile = $files[$i].BaseName + $newext     
       Start-Process $files[$i].FullName -verb Print | out-printer -name "Page Segment Print File"  
       start-sleep -Milliseconds $focus
   [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
   start-sleep -Milliseconds 250
   [System.Windows.Forms.SendKeys]::SendWait($(Join-Path $rootdir $newfile))
   start-sleep -Milliseconds 250
   [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
   start-sleep -Milliseconds 1500
   $focus = 250
}
Write-Verbose "Print Files Generated"`

这篇关于将 Powershell Out-Printer 用于文件时控制输出位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆