How to use Powershell Forms to create and fill printable doc

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
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.
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
bembree
Posts: 18
Last visit: Tue Nov 07, 2017 10:50 am

Re: How to use Powershell Forms to create and fill printable doc

Post by bembree »

jvierra wrote:The real issue here is that old thing about printing a form from a GUI with PowerShell. There is really no internal method in forms or PowerShell, PowerShell Studio to do this.

This issue came up a few years ago and I had to apply my knowledge of printing in C# to PS. I found the old form (it was still a V1 PFF file) and cleaned up the code to make a simple demo of how to print the form on the screen to a printer. This version prints the complete form.

We could just print the client portion of the form with no "chrome" or design a custom output form and print that. It will all be very similar to using MSAccess to generate a fancy filled in form. A little extra code and we could print pages of data records on separate documents. We can even convert to PDF if you have Office 2016 installed or have installed PDF support in Office 2010.

Here is the demo form. It has both "Preview" and "Print" buttons. The code can be added to any form and it will print the form. Maybe I will create a custom control set later or you could easily do it yourself off of this demo.

See the MS documentation for the two controls for printing and print preview. They are very rich with adjustments to the resulting dialogs and behaviors.

[System.Drawing.Printing.PrintDocument] https://msdn.microsoft.com/en-us/librar ... .110).aspx
[/url][/url][System.Windows.Forms.PrintDialog] https://msdn.microsoft.com/en-us/librar ... .110).aspx
[System.Windows.Forms.PrintPreviewDialog] https://msdn.microsoft.com/en-us/librar ... .110).aspx
I am unable to open the psf file in PS Studio. No errors; it just won't open. I unblocked the file too. Any suggestions?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to use Powershell Forms to create and fill printable doc

Post by jvierra »

bembree wrote:
DevinL wrote:Unfortunately, this seems more like a scripting based question as opposed to a product specific question. If so, then this belongs in the Windows PowerShell or PowerShell GUIs forum so the community can help out with this.

That being said, they're going to need more information to go off of such as what you've got so far for your script, what you've tried and what kind of information exactly you're wanting to get about your PC's.

Are you referring to the Sapien forums or the regular Powershell forums, like TechNet?
The Sapien - ScriptingAnswers.com forums. Don't worry. Your question was moved to the correct forum.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to use Powershell Forms to create and fill printable doc

Post by jvierra »

bembree wrote:
I am unable to open the psf file in PS Studio. No errors; it just won't open. I unblocked the file too. Any suggestions?
I just downloaded it and it works fine. There is nothing i the code that would prevent the file from opening. You must have PSS 2015 or later to open it.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to use Powershell Forms to create and fill printable doc

Post by jvierra »

Suggestion: Open file in notepad to be sure you have a good file with both opening and closing elements

<File version="2.1">
</File>

Open one of your recent PSF files and look at the version.
User avatar
AdamUK
Posts: 31
Last visit: Fri Jun 22, 2018 2:29 am

Re: How to use Powershell Forms to create and fill printable doc

Post by AdamUK »

Just wanted to say thanks for posting the printing demo form, managed to use this in one of my forms yesterday :D sharing knowledge is great
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: How to use Powershell Forms to create and fill printable doc

Post by jvierra »

AdamUK wrote:Just wanted to say thanks for posting the printing demo form, managed to use this in one of my forms yesterday :D sharing knowledge is great
Next try to draw pictures on the page using $_.Graphics and the many drawing tools like ellipse and lines, colors and brushes. It is MsPaint in a set of metods.

https://msdn.microsoft.com/en-us/librar ... .110).aspx
This topic is 7 years and 2 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked