Merge PDF based on filename prefix

Posted on 2015-01-27
Last Modified: 2015-01-29
I need to merge PDF's based on file name/file prefix.  I have two sets of PDFs each beginning with the same 10 characters.  I would like to merge PDF file  0123456789Rpt.pdf with 0123456789.pdf - file 9876543210Rpt.pdf would be merged with 9876543210B.pdf so on and so forth.  Ideally the resulting merged file should be named with the same 10 character prefix and end in *Rpt.  This question is pretty much the same as the question that was answered below, but I cant seem to follow the solution....
Question by:deskchains
  • 5
  • 3
LVL 53

Expert Comment

by:Joe Winograd, EE MVE
ID: 40573236
In addition to the question you showed above, here's another similar one:

One of my posts in that question refers to an article (with a program) that I wrote:
How To Combine-Merge-Append a Large Batch of TIFF Files

It shouldn't be difficult to modify that program to do what you need. Two things would need to be changed:

(1) Use the /multipdf parameter instead of /multitif.

(2) Make the name of the merged file 0123456789Rpt.pdf instead of 0123456789.pdf.

If you can make those modifications yourself, great; if not, let me know and I'll try to help. Regards, Joe

Author Comment

ID: 40576313
Thanks Joe,

I installed IfanView and AutoHotkey - plus ghostscript and the ifanview plugins.  I removed the /multitif parameter and used /multipdf - and also had to replace ever instance of .tif with .pdf.  Works, but doesn't do it all on its own; when it processes one set of files a series of windows come up with additional save options.  It will do this for every set of pdf's you are trying to merge.  Does this happen when you are processing tif's?
LVL 53

Accepted Solution

Joe Winograd, EE MVE earned 500 total points
ID: 40576513
Ah, sorry about that. I should have anticipated that issue. No, it doesn't happen with TIFs. It happens with PDFs because of the plugin that IV uses. Here's how to fix it.

IV uses a PDF plugin called ImPDF to be able to save/write PDFs (it uses Ghostscript to interpret/render/view PDFs). There's an ImPDF section in your IV configuration/settings file, <i_view32.ini>. It will begin with this:


There's a line in that section that looks like this:


Change it to:


That's it!

Btw, the <i_view32.ini> file is in the install folder, but in W7/W8, it usually just points to the "real" one. In other words, the one in <Program Files (x86)> usually looks like this:


So to find the "real" config file with the [ImPDF] section (and all other IV settings), look in %AppData%\IrfanView, which is usually:


A few other points for you:

(1) You said that you downloaded GS. Make sure you installed the 32-bit version (even if your OS is 64-bit), because IV is a 32-bit program and needs the 32-bit GS. If you installed the 64-bit GS, uninstall it and install the 32-bit one.

(2) In addition to replacing all of the "TIF" occurrences with "PDF", replace the "TIFF" ones with "PDF".

(3) Remove the TIFF compression logic — everything from:




Also, remove all of the:

If (Compression=N)

statements near the end, as well as:

Compression method used: %compmeth%

in the operational statistics.

And remove the:


parameter from the RunWait,%IVexe% statement.

That's everything off the top of my head, but let me know if you run into other issues. I may modify my TIFF article to support PDF, or maybe just write a new one specifically for PDF, but let's get you up-and-running first. Regards, Joe
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Author Closing Comment

ID: 40577575
Thanks again Joe.

I modified the ini file and no longer have the preview issue.  I didn't specifically mention it in my previous comment that one of the windows had to do with  "security"  prompting for a password.  I looked at the ini file again and set:


and the merging of the PDF goes like a snap.  Great Job and thanks so much

Author Comment

ID: 40577592
I did not however figure out how to make/choose the final name of the PDF.  0123456789Rpt.pdf combined with 0123456789.pdf results in a combined pdf named 0123456789.pdf.
LVL 53

Expert Comment

by:Joe Winograd, EE MVE
ID: 40577606
That's great news! Thanks for the explanation of the Security issue. I haven't experimented with any of the Security parameters in the [ImPDF] section, so it's good to hear about your experience with it.

If you get a moment to go to the article and click the big green Vote this article as helpful button, I'd really appreciate it. Regards, Joe
LVL 53

Expert Comment

by:Joe Winograd, EE MVE
ID: 40577641
Our messages just crossed, so I missed the <Rpt> naming issue. I could add a prompt asking for a suffix, which would be applied to every file name after the merge. You could enter <Rpt> or <Report> or <_report> or whatever you want. I think a good place for this prompt is after the "Enter the number of first characters..." prompt and before the "Browse For Folder" dialogs. Sound good?
LVL 53

Expert Comment

by:Joe Winograd, EE MVE
ID: 40577930
Although I didn't hear back from you on the Suffix idea, I decided to go ahead with the enhancement. There are two approaches. The first is a simple, one-line change that hard-codes <Rpt> in the merged file name. To do that, change:




That's it! The Rpt characters in that line may, of course, be anything you want, such as Report or _report or whatever.

The second approach is the general solution that I was referring to in my previous post, allowing the user to enter any suffix. For this, you'll need to make these three changes:

(1) After the closing right brace of the Loop that inputs the number of first characters, add this code to input the suffix:

  InputBox,Suffix,Suffix,Enter a suffix for all merged file names`n(leave box empty and click OK for no suffix`nor click Cancel to exit)
  If ErrorLevel
  If BadVarWin(Suffix)
    MsgBox,53,Error,The following characters are invalid in a Windows file name:`n`n< > : " / | \ ? *`n`nclick Retry to try again or Cancel to exit

Open in new window

(2) Change this line:


to this line:


(3) Add this code at the bottom (after the <MsgBox,0,Operational Statistics Saved...> line):


  Loop %FileCharsLen%
    If InStr(BadCharsWin,FileCharsCheck)
      Return True
  Return False

Open in new window

I added this code to my script here and it works perfectly, but let me know if you have any problems. Note that the ExitApp line at the top of the code above is very important. Regards, Joe

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB Script: create txt file with DateStamp and IP Adress 6 27
powershell script 9 67
Records from Access to Excel to specific cells 5 29
Having trouble with a VB Script 17 18
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question