Printing & PowerShell; Thoughts?

Ask your Windows PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
zmilbourn
Posts: 8
Joined: Thu May 05, 2016 10:37 am

Printing & PowerShell; Thoughts?

Post by zmilbourn » Thu Sep 27, 2018 2:57 pm

Hello all,

I am coming to PS Studio with experience from another development studio (of which I shall omit the name so there's no conflict of interest). In the aforementioned programming suite, I could create a printer canvas object, write text and graphical elements to the object, and then simply send it to the printer on the end user's machine (the user running the application). I have found printing more difficult in PowerShell - and by extension, in PowerShell Studio.

So far, I have tried to print by passing to the MS Word executable, the Wordpad executable, and even the Internet Explorer executable. Although I can get usable printouts using these methods, I find these solutions very "dirty." I am curious if there's any really slick printing solutions that you all are aware of that could be utilized to print "rich text" from an end user's machine, using only PowerShell.

I am not versed in C# or .NET, but I imagine folks would be utilizing System.Drawing.Printing in some way to achieve this. As a self-admitted novice to .NET framework, I am unsure how to work up something from scratch to achieve the aforementioned results ("rich text" printing) via PowerShell

I would love to hear your thoughts on this! Thank you.

User avatar
jvierra
Posts: 13736
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Printing & PowerShell; Thoughts?

Post by jvierra » Thu Sep 27, 2018 3:08 pm

Yes. We use the Net Printing classes to create a graphical context and use standard System.Drawing methods to write into the graphical context (Canvas).

Attached is a simple example.
Attachments
Demo-PrintDocument3.psf
(15.65 KiB) Downloaded 75 times

User avatar
zmilbourn
Posts: 8
Joined: Thu May 05, 2016 10:37 am

Re: Printing & PowerShell; Thoughts?

Post by zmilbourn » Fri Sep 28, 2018 10:37 am

Thanks very much!

Locked