Carl Burks is a software developer for a global financial institution. With over ten years experience in technology and software development for financial organizations and over twenty years of software experience, Carl Burks provides articles, musings and insight into technology issues, software development, and other selected topics.

Combining PDFs with PDFTK Into a Folder by Year and Month

2018-11-25T09:15:06.000-07:00

Authors:
Carl Burks

Learning PowerShell

First downloading the Language Specification from Microsoft will give you a good start into how to use PowerShell. https://www.microsoft.com/en-us/download/details.aspx?id=36389

Comments

In PowerShell a comment begins with the octothorpe #

# This is a comment it doesn't actually do anything it just lets you write notes.

In the language specification you can read about comments in the section 2.2.3.

Getting help

You might read section 13.19 in the Language Specification to learn about how to get help, or run in PowerShell

get-help

https://docs.microsoft.com/en-us/powershell/module/Microsoft.PowerShell.Core/Get-Help?view=powershell-6

Control of Flow

Control of Flow is how your program runs. Wikipedia does a pretty good job of explaining it.

Here is a PowerShell Specific explanation:

https://www.oreilly.com/library/view/windows-powershell-cookbook/9781449359195/ch04.html

Loops

To learn about loops read here: https://blogs.technet.microsoft.com/heyscriptingguy/2014/04/28/basics-of-powershell-looping-foreach/

Commands Used

Special Variables

Sometimes you want to use "My Documents" from PowerShell.

Here is how to use that:

[environment]::getfolderpath("mydocuments")

Want to learn more: https://blogs.technet.microsoft.com/heyscriptingguy/2012/02/20/the-easy-way-to-use-powershell-to-work-with-special-folders/

PDFTK

O'Reily has a book called PDF Hacks and they have a website for the book.

http://www.pdfhacks.com/

One of the tools described is PDFTK.

This is a great tool to learn for manipulating PDFs.

PDFLabs has the manpages for using the tool here.

https://www.pdflabs.com/docs/pdftk-man-page/

Here is the download page:

https://www.pdflabs.com/tools/pdftk-server/

When you install it, don't uncheck the add to path button. We will need it in the path for the example script.

Putting them together

Here is a script: https://www.burksbrand.com/static/powershell_pdftk_month_folder_example.ps1

The script will give you a warning telling you to only run scripts you trust. Running a script from the internet can be dangerous. It is important to read and understand what the script is doing before attempting to run it.

The script has been commented for ease of use of someone not familiar with PowerShell.

You can view it in VS-Code or PowerShell ISE which is built in.