Thursday, May 28, 2009

PDFs with Powershell and PDF Sharp

I found this script today on the internet searching as I do everyday for anything new with powershell. I was searching to see if itextsharp could be used to create PDFs with Powershell and stumble onto the script below that shows how to do it with PDF Sharp.

http://www.pdfsharp.net

Code:

param($text="Hello World",$fileName="c:\test.pdf")

[reflection.assembly]::loadfrom("C:\Downloads\Powershell\PDFSharp\bin\PdfSharp.dll") | out-null

# Create a new PDF document
$document = new-object PdfSharp.Pdf.PdfDocument

# Create an empty page
$page = $document.AddPage()

# Get an XGraphics object for drawing
$gfx = [PdfSharp.Drawing.XGraphics]::FromPdfPage($page)

$options = new-object PdfSharp.Drawing.XPdfFontOptions([PdfSharp.Pdf.PdfFontEncoding]"Unicode", [PdfSharp.Pdf.PdfFontEmbedding]"Always")

# Create a font
$font = new-object PdfSharp.Drawing.XFont("Arial", 20, [PdfSharp.Drawing.XFontStyle]"Bold", $options)

# Draw the text
$gfx.DrawString(
$text,
$font,
[PdfSharp.Drawing.XBrushes]::Black,
(new-object PdfSharp.Drawing.XRect(0, 0, $page.Width, $page.Height) ),
[PdfSharp.Drawing.XStringFormats]::Center)

# Save the document...
$document.Save( $filename )

Wednesday, May 27, 2009

Powershell GUI

Your number one stop when learning Powershell should be PowerGui. PowerGui allows you to take advantage of Powershell without any coding, but if you prefer to code there is the PowerGui Editor that I use on a daily basis.

Other items you will find on the PowerGui.org site are:

  • Remote WMI Defrag

  • Active Directory Powerpack from Quest Software

  • Network Power Pack

  • Exchange PowerPack

  • Twitter Powerpack


The combination of the Active Directory and Exchange Powerpacks has allowed my team to full automate End-User Provisioning.

A 4 part series on User Provisioning can be found on Technet at:

http://technet.microsoft.com/en-us/magazine/2009.03.windowspowershell.aspx
http://technet.microsoft.com/en-us/magazine/2009.04.windowspowershell.aspx
http://technet.microsoft.com/en-us/magazine/2009.05.powershell.aspx
http://technet.microsoft.com/en-us/magazine/dd797567.aspx