How To Rename a Batch of PDF Files Based on Contents of the Files

I have a batch of PDF files that I need to rename using a Powershell Script and the new filename will grab text from a field inside the pdf and replace the last part of the filename

e.g.
* The original PDF Filename is "735420 - 11678 - Flemington .pdf"
* The field "Customer ID" on the first page of the PDF has the words "24567"
* I want to keep the first two numbers "735420 - 11678" and rename the rest of the filename to include the customer id "24567"
* The new filename will be "735420 - 11678 - 24567.pdf"

I am quite new to Powershell Scripting, so any help would be great.

I did have a look at this article http://www.experts-exchange.com/articles/11211/How-To-Split-Rename-Move-a-Batch-of-PDF-Files-Based-on-Contents-of-the-Files.html but seems quite complex.
Troy GrahamIT ManagerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Troy,

Yes, it's complex, although you don't need the added complexity of the Split-Rename-Move program — based on your description, it seems that you need just the Rename-Move program. But even that program is complex —  491 lines of code (not including comment lines).

I can't help you with a PowerShell version, and I'm not in a position yet to re-post the AutoHotkey source code, but I could probably send you an executable that does what you want. If that interests you, drop me a message via the Messaging System; if that doesn't interest you, then perhaps a PowerShell expert will jump in to help you. Regards, Joe
Troy GrahamIT ManagerAuthor Commented:
Hi Joe,

If you could get me an executable that will do what I am asking would be Awesome.

Look forward to hearing back from you soon.
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Troy,
I'll need a sample PDF. If you want to post it here, that's fine, but realize that it's public; if you prefer it not to be public, send me a message via the EE Messaging System and I'll give you my email address (EE doesn't allow posting email addresses in comments). In either case, be careful not to have private/sensitive data in the sample file. Regards, Joe
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Troy GrahamIT ManagerAuthor Commented:
Hi Joe,

Sorry to be a pain, but would it be difficult to also create an exe file to perform the same function from an Excel CSV File (instead of PDF) and rename PDF's in same directory
Joe Winograd, Fellow&MVEDeveloperCommented:
> perform the same function from an Excel CSV File (instead of PDF)

Where would it find the "Customer ID" field in the CSV? On the PDF, you said it would be on the first page. In the Excel file, would it be in a specific cell?

> and rename PDF's in same directory

Now I'm confused. If the input is "an Excel CSV File (instead of PDF)", then why would there be any PDFs?
Troy GrahamIT ManagerAuthor Commented:
Hi Joe,

Apologise for the confusion.

let's stick to the original PDF version

Inside PDF field are the following fields below that we need to include in filename

Site # 1234
Site Name: JOE BLOE WOY WOY
Customer Reference: 12345678
Date: 24/07/2015
ECL Call Type: DC

So the filename will be

1234 - JOE BLOE WOY WOY - 12345678 - DC - JULY-2015.PDF

Can this be done ?
Joe Winograd, Fellow&MVEDeveloperCommented:
> Can this be done ?

Yes, but it's well beyond your initial request. Based on your original post, I thought there was one field that needed to be part of the renaming — the string following Customer ID (and that's what my program already does — looks for a single "Identifier" field). But now I think you're saying that there are five fields that need to be part of the renaming:

Site #
Site Name
Customer Reference
Date
ECL Call Type


Also, you want the Date field converted from DD/MM/YYYY to MonthFullName-YYYY for the renaming. All of that can be done, but it's beyond the scope of gratis work here at EE. If you'd like to click the Hire Me button in my profile, we can talk further about it. Regards, Joe

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Qlemo"Batchelor", Developer and EE Topic AdvisorCommented:
Please have a look at using iTextSharp DLL
Download: http://sourceforge.net/projects/itextsharp/
Two usage cases:
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1268809d-5dc6-4cd2-a97f-a26bc3ae3a8b/using-powershell-to-parse-a-pdf-file
https://gallery.technet.microsoft.com/scriptcenter/Use-Powershell-to-Fill-3f28ba21

I do not have a PDF with form elements ATM to try myself. But if you can get to the content that way, renaming the file gets easy (as soon as I know how to reliably close the PDF after working with it, that is).
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.