Omglolyes
Omglolyes

Reputation: 184

Using Out-Printer within a script

So the mentioned method is from here (https://www.powershellgallery.com/packages/6Print/0.1.0/Content/Out-Printer.ps1)

I have been stuggeling with this, because while the method works fine while in command-prompt, it will fail in a script, whatever i do.

So my input is a .tif image and i want to print a pdf. So in the shell i would try something like

>cd desktop
>. .\out-printer
>Out-Printer -ImagePath $env:userprofile\desktop\test.tif -PrinterName 'Microsoft Print to PDF' -PrintFileName $env:userprofile\Desktop\test.pdf -LandScape -PaperSize a4

Which would be fine. But lets say i add the function 'test' to the bottom or top of 'Out-File.ps1' which looks like this right now:

function test(){
Out-Printer -ImagePath $env:userprofile\desktop\test.tif -PrinterName 'Microsoft Print to PDF' -PrintFileName $env:userprofile\Desktop\test.pdf -LandScape -PaperSize a4
}

and execute with > . '.\Out-Printer.ps1'; Test

This givs me an error starting with:

New-Object : Der Typ [System.Drawing.Text.InstalledFontCollection] kann nicht gefunden werden. Stellen Sie sicher, dass die Assembly, die diesen Typ enthält, geladen wird. In C:\Users\erdmannr\desktop\Out-Printer.ps1:78 Zeichen:27 + ... lledFonts = New-Object -TypeName "System.Drawing.Text.InstalledFontCo ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException + FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand

This goes on for a while, and most errors are about [System.Drawing.*]

Please help, i just want to print a .tif to a *.pdf =)

Upvotes: 0

Views: 1065

Answers (1)

Mathias R. Jessen
Mathias R. Jessen

Reputation: 174445

Looks like Out-Printer does not automatically loads some dependencies.

You can can load the System.Drawing.dll assembly manually with:

Add-Type -AssemblyName System.Drawing

Upvotes: 1

Related Questions