Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Merge PDF based on filename prefix

Posted on 2015-01-27
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
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 56

Accepted Solution

Joe Winograd, EE MVE 2015&2016 earned 2000 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
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 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
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 56

Expert Comment

by:Joe Winograd, EE MVE 2015&2016
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

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

636 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