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 Cover Page to Word with PowerShell

6/14/2016

0 Comments

 
Picture
​I needed to add a cover page to many documents and decided to automate the process with PowerShell.  The real issue was to only add a cover page if one doesn't already exist.
Summary:
The below script will open a given document, check if a cover page exists and add one if it doesn't

Problem Overview:
Need to detect if a cover page exists and add one if it doesn't.

Solution:
I decided to create a cover page first by making a separate document that contains just the cover page I want to add and then combining it with the document that I want to add it to.

It is simple enough to create a custom cover page.  Combining two documents is not too hard either.  Detecting if a cover page already exists is what began to cause me issues.

I tried to see if there was any special "cover page only" attributes that got added when you used one of the OOTB templates.  All of these templates just appeared to have document controls, shapes, and typical formatting.  Nothing stood out initially and I couldn't find any standard method to see if one exists via code.

I then noticed that all of the OOTB templates have a content control with a label of "Title".  I decided to use that as my search term so my solution outline would become:
  1. Open document.
  2. Search all content controls in document for one that has a title of "Title".
  3. Add cover page or not.

Limitations:
I am assuming any cover page that may exist has a content control with a title part named "Title."  If you made the cover page yourself, then you may put something else for title so you will need to compensate for that.

Even though the OOTB cover pages use such a content control, you may have even added one with the same title somewhere else in a document that doesn't actually have a cover page.  Again, you will need to compensate for this as well.

How to Use:
Save the script as "WordCoverPage.ps1" and run in either one of two ways:
PowerShell:
./WordCoverPage <full file location> <full cover page location>
Command Prompt:
powershell -command "<full script location> <full file location> <full cover page location>"

Tips:
Create a ForEach loop to run this on a directory full of files.
​WordCoverPage.ps1

    

Search Links:
  • How to Detect if a Cover Page Exists in Word with PowerShell
  • How to Change the Value of a Content Control Object in Word with PowerShell
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