简体   繁体   English

将Powershell Out-Printer用于文件时控制输出位置

[英]Control output location when using Powershell Out-Printer to a File

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. 我有一个Powershell脚本,它从服务器上的文件夹中检索所有图像文件(.jpg,.png)并将它们“打印”到文件,特别是使用特定打印驱动程序的.prn文件。 All of that works fine. 所有这一切都很好。 The issue is that I can't work out how to control where the output of "printing" goes, ie where it puts the resulting .prn file. 问题是我无法弄清楚如何控制“打印”输出的位置,即它放置生成的.prn文件的位置。 They always go to the Pictures folder on my PC. 他们总是去我电脑上的Pictures文件夹。 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. 在上周,我已经搜索了Powershell out-print,out-file等的所有组合,我可以考虑尝试但到目前为止没有找到解决方案。 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"`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM