Home HowTo Export Data Sending Results to PDF Files
 

Sending Results to PDF Files

Outputting PowerShell results to text files is convenient yet not perfect. Users can easily change text files, and results may be incomplete, truncated by the PowerShell ETS system.

A much more professional approach would be sending results to PDF files. Now there is free PDF support in PowerShell! With our free module you can use Out-PTSPDF to send any result to a PDF file and enjoy creating sophisticated PDF reports for free in no time.

The module comes with all that is needed. You do not need any additional software and can start producing your own PDF reports even on servers with limited software.

Out-PTSPDF PDF file generator
222.5 KiB
1403 Downloads
Details...

Downloading and Installing

Just download and unpack the module. If you need assistance, take a look at http://www.powertheshell.com/installpsmodule/. Like any other script based PowerShell module, it is a simple copy&paste deployment. No special privileges needed.

Once in place, you simply need to import the module:

Import-Module PDFTools

This adds a new command called Out-PTSPDF. It has plenty of parameters to help you generate the PDF in just the way you want it.

Generate PDF Reports
Out-PTSPDF can turn any PowerShell result in a PDF file

Out-PTSPDF supports autosize, for example: it makes the PDF wide enough to display all content without truncating anything. You can choose different fonts and sizes, include page headers and more.

Example Reports to Play With

Here are some example calls that illustrate how you can use the parameters:

Get-Process | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -AutoSize -FontName 'Times New Roman' -FontSize 8

Get-Process | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -AutoSize

Get-Process | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -Width 120

Get-Service | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -AutoSize -Property Name, DisplayName, ServiceType -GroupBy Status

Get-Service | 
  Sort-Object Status | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -AutoSize -Property Name, DisplayName, ServiceType -GroupBy Status

Get-Service | 
  Sort-Object Status | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -AutoSize -Property Name, DisplayName, ServiceType -GroupBy Status -FontSize 7

Get-Service | 
  Sort-Object Status, Name | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -AutoSize -Property Name, DisplayName, ServiceType -GroupBy Status -FontSize 7

Get-WmiObject -Class win32_service | 
  Sort-Object StartMode, DisplayName | 
  Out-PTSPDF -Path $env:temp\report.pdf -Open -AutoSize -Property DisplayName, State, ExitCode, PathName -GroupBy StartMode -FontSize 6 -IncludeHeader -HeaderText 'List of Services - Page {0}'

Getting Help

Out-PTSPDF comes with rich help so you can examine its parameters and browse the examples.

You can either call help and view the information separately:

help Out-PTSPDF -Parameters *
help Out-PTSPDF -Examples

Or, if you use PowerShell 3.0, you can view help in a separate viewer:

help Out-PTSPDF -ShowWindow
Complete help builtin

view the help and explore the many examples

Credits

At its heart, Out-PTSPDF uses the free and open-source library PDFSharp which enables it to generate PDF files without any additional software. The binaries are part of the module so you don’t need to install anything else. Note however that if you specify the parameter -Open to open the generated PDF file, you will need a third party PDF viewer of course.

Now we hope you enjoy our latest module. If you live in Europe and look for professional PowerShell training, we might have what you want. Just drop me a line: [email protected]. We do trainings throughout Europe in German and English. We also specialize in PowerShell coaching, project support and any PowerShell related specialty you might be interested in.

 

Facebooktwittergoogle_pluspinterestlinkedinFacebooktwittergoogle_pluspinterestlinkedin  rssrss
Out-PTSPDF PDF file generator
Out-PTSPDF PDF file generator
PDFTools.zip
Version: 1.0
222.5 KiB
1403 Downloads
Details...
The following two tabs change content below.

Tobias

PowerShell Wizard at scriptinternals
I love to create things and master challlenges. That's why I love PowerShell so much. I am a 10+ year Microsoft MVP, have written more than a 100 IT-related books with Microsoft Press and others, and like to expain complex things in a simple and understandable way. I am giving PowerShell trainings throughout Europe and organize the annual German PS Community Conference.

  • Richard

    Finally something simple to incorporate with my scripts.

    Any chance for a more detailed explaination of the parameters?
    How about something to dress up the output a bit?

    So far it’s worked great but what I’m using it for is very simple to say the least.

    Thanks.

  • Richard, glad you like it.

    Actually, the module was just something I played with to create simple PDF reports without additional 3rd party software requirements.

    For that, the module was always sufficient. That’s when I decided to share it with anyone interested.

    This said, the module is plain PowerShell code wrapped around an open-source dll that exposes the PDF magic.

    So if you like, simply open the module folder and have a look. It is all yours, and you can add more parameters and explore what the existing ones do.

  • Richard

    Thanks. I’m still pretty green with Powershell. Could you give me a little boost? What I’d like to do is add a -Title [text] [color]. I can see that it would be a function but I’m stumped at that point.

    Thanks.

  • You can do that already, except for the color. Try the parameters -HeaderText Blabla and -IncludeHeader. This will at least add a repeating header text on the top of each page.

    Open Out-PTSPDF.ps1 inside the module folder to see all parameters. Here, you would have to add your new parameter.

    Next, look at AddHeader. It is responsible for adding the page header text. It uses the $gfx.DrawString method to write text to the PDF.

    You would have to write your own function that writes the header text, then find a good place where to call it. You probably would want to include it in the function Add-Line, but only inside the block that starts with if($isPDF) (since you want your header only to appear on the first page).

    Hope that gets you started. Make sure to backup the script before you change it 😉

  • techvet

    “help Out-PTSPDF -Parameters *” doesn’t work for me. However, “help Out-PTSPDF -Examples” and “help Out-PTSPDF -ShowWindow” do work.

  • Pingback: Create PDF from Sql with Powershell | The Persistent Weblog()