1

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"
Qui-Gon Jim
  • 13
  • 1
  • 5
  • This is going to be configured in your print driver not in powershell anywhere. – Nathan Rice Mar 04 '15 at 18:35
  • Thanks for the suggestion. I had a look and the driver does not appear to have any provision for setting an output path. When using the driver manually, i.e. open an image in Paint for example and print it with the driver in question, a standard Save File dialog comes up. That is related to what the script is doing inside the For Loop. It's setting the output file name. If i could work out how to get it to also set the folder to output to I'd be all set. There can be as many as 10,000 images in the folder to process and this is only the first step. – Qui-Gon Jim Mar 04 '15 at 19:06
  • 1
    when defining the name set a full path instead of just the name. "C:\Temp\$newfile" – ATek Mar 04 '15 at 19:17
  • 1
    Full Path works perfectly. I have no idea why that never occurred to me. The simplest answers are usually best. Thanks – Qui-Gon Jim Mar 04 '15 at 19:26
  • @Qui-GonJim - Posted an answer response with a full example, couldn't test any of your other code because its kind of unique. – ATek Mar 04 '15 at 21:13

1 Answers1

0

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"`
ATek
  • 815
  • 2
  • 8
  • 20