I currently working on a script to automate the printing process to increase our workflow at work. However eveything is working as it should but i cant force the printer to print in duplex mode. The printer has the option to use that kind of mode (I used that for the working process before).
Like you see within the code (at the end of the post) I am using the Set-PrintConfiguration cmd on powershell. If I ask for the configs with Get-PrintConfiguration the Duplexing mode is on TwoSidedLongEdge (which is what I want) but the printer isnt printing in duplex mode, instead I get only one sided pages. Thus I have the option to set the printer manual on duplexing mode within the printer options but I dont want to do that. I want that everyone could use the script without setting the printer options manually.
I dont know what the problem could be. I am using the ComObject method to work with the already existing word documents. Therefore I use the .PrintOut() mehtod to print the documents (mabye this is the problem?). I tried to use the param "ManualDuplexPrint" to enforce duplex printing but this isnt working either.
I my optionion the important part is in the "Set print configs" of the code.
I hope you can help. If you have further questions, dont hesitate to ask. :)
Set print configs
Get-Printer -Name "ECOSYS M6630cidn" | Set-PrintConfiguration -DuplexingMode 'TwoSidedLongEdge' Get-PrintConfiguration -PrinterName "ECOSYS M6630cidn"
Snippiet of the printing code
` $Word = New-Object -ComObject Word.Application
try {
$doc_out = $Word.Documents.Open($path_out)
$doc_in = $Word.Documents.Open($path_in)
$doc_list = $doc_list + $doc_out + $doc_in
}
catch {
[System.Windows.Forms.MessageBox]::Show(
"Dokumente konnten nicht geladen werden. Stellen Sie sicher, dass die Dokumente Ausgabeprotokoll und Rueckgabeprotokoll im Ordner liegen.", "Error", 0
)
}
foreach ($doc in $doc_list) {
### Find and replace text in Ausgabeprotokoll
$find_SN = "SN"
$find_GN = "GN"
$replace_SN = $text
$replace_GN = $var[$text]
$matchCase = $false
$matchWholeWord = $false
$matchWildcards = $false
$matchSoundsLike = $false
$matchAllWordForms = $false
try {
$doc.Content.Find.Execute($find_SN, $matchCase, $matchWholeWord, $matchWildcards, $matchSoundsLike, $matchAllWordForms, $true, 1, $false, $replace_SN, 2)
$doc.Content.Find.Execute($find_GN, $matchCase, $matchWholeWord, $matchWildcards, $matchSoundsLike, $matchAllWordForms, $true, 1, $false, $replace_GN, 2)
}
catch [System.Management.Automation.RuntimeException]{
[System.Windows.Forms.MessageBox]::Show(
"Zugriff auf Dokument nicht möglich.", "Error", 0
)
}
# Write-Host "Printing"
$ManualDuplexPrint = $true
$doc.PrintOut($ManualDuplexPrint)`