Erick's Blog
  • Home
  • Blog
  • Apps
    • Mortgage Calculator
  • PowerShell
    • Blog & Examples
    • Excel Reference
  • Windchill
    • Document Exporter
    • Document Worker
    • E.P.L.E.S.
    • Export Released
    • Property Checker
    • Windchill Business Analytics >
      • Part 01 - Program Logic
      • Part 02 - Getting Data with SQL Queries
      • Part 03 - Automating SQL Queries
      • Part 04 - Converting SQL Results to XML
      • Part 05 - Data Processing and Manipulation
      • Part 06 - Displaying XML in HTML
      • Part 07 - Auto Updating Displayed Data
      • Part 08 - Hosting Webpage with an Existing Apache Installation
      • Part 09 - Running Multiple Queries In Sequence
      • Part 10 - Calculating Data Trends
      • Part 11 - Making It Modular
    • Windchill Quick View
  • Reviews
  • Music
  • Contact

How to Add a Signature Image to a Word Document with PowerShell

6/5/2016

0 Comments

 
Picture

Adding your signature to digital documents isn't too difficult to do but what if you need to automate the process in a certain PDM/PLM system?  This PowerShell script is the snippet of code I used to auto sign documents during Windchill publishing.

June 8, 2016: Updated to 1.1 with auto image resize.

Version History:
1.1: Signature auto resize added, June 8, 2016
1.0: Initial release, June 5, 2016
​
Summary:
The below script will automate the process of adding a digital signature image to Word documents.

Problem Overview:
I needed a way to to automatically add a signature to approved documents when they got published in Windchill.  Leaving out the Windchill part for now and making this script a "general use" script, I have trimmed the code to just show the relevant signature part.

Limitations Encountered:
(Fixed in version 1.1.) I have yet to find a way to auto-size shapes based on the picture fill so you should make sure to adjust all signature files to have the appropriate ratio as I have talked about in the How to Watermark Word Dcouments with PowerShell guide.  Adding white space around the signature image to get the correct ratio if you have multiple names with varying lengths would also work.

Solution:
Just like the previous watermarking code, I am essentially doing the same thing here.  Adding a shape, changing the fill, removing the lines.  The new requirements is that I need only one signature on every document and it needs to be in a specific place on the document.  I needed to find a way to specifically place the signature on the signature line.

I realized that you can add a title to a shape and then search for the shape via PowerShell so that is what I decided to do.  Instead of having my script create the shape, I needed it to already be there and aligned on the signature line.  I added the fill manually to check the signature location and also made sure to adjust the shape to be above the signature line.
Picture
Once the alignment was complete. I removed the picture fill and ran the code.  Here is the final result:
Picture
How to Use:
Save the script as "WordSignature.ps1" and run in either one of two ways:
  1. PowerShell:
    1. ./WordSignature <full file location> <full watermark location>
  2. Command Prompt:
    1. powershell -command "<full script location> <full file location> <full watermark location>"
Tips:
Be sure that all signatures are in a format that removes the background such as .png or .gif.  I have made mine via a simple WordArt .png made in PowerPoint.  You can similarly use the Shapes -> Scribble option in PowerPoint to allow people to manually draw their signatures via a tablet or mouse before exporting them as .png files.

Notes for Release:
1.1: The size of the initial shape you choose is what defines the max allowable size of the inserted signatures. ($SigMaxH, $SigMaxW)
1.0: (Fixed in version 1.1.) If you are going to use multiple names as signature, make sure to adjust the ratios of all pictures to be the same to avoid shrinking or stretching issues.
WordSignature.ps1

    
0 Comments



Leave a Reply.

    Author

    PLM engineer while "on the clock", programmer, designer, dreamer all other times.

    Archives

    August 2016
    June 2016

    Categories

    All
    Cover Page
    Excel
    Office
    PDF
    PowerShell
    Reference
    Signature
    Watermark
    Word

    RSS Feed

Copyright © 2018 Erick Johnson
  • Home
  • Blog
  • Apps
    • Mortgage Calculator
  • PowerShell
    • Blog & Examples
    • Excel Reference
  • Windchill
    • Document Exporter
    • Document Worker
    • E.P.L.E.S.
    • Export Released
    • Property Checker
    • Windchill Business Analytics >
      • Part 01 - Program Logic
      • Part 02 - Getting Data with SQL Queries
      • Part 03 - Automating SQL Queries
      • Part 04 - Converting SQL Results to XML
      • Part 05 - Data Processing and Manipulation
      • Part 06 - Displaying XML in HTML
      • Part 07 - Auto Updating Displayed Data
      • Part 08 - Hosting Webpage with an Existing Apache Installation
      • Part 09 - Running Multiple Queries In Sequence
      • Part 10 - Calculating Data Trends
      • Part 11 - Making It Modular
    • Windchill Quick View
  • Reviews
  • Music
  • Contact