Solved

Merge PDF based on filename prefix

Posted on 2015-01-27
8
170 Views
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....

http://www.experts-exchange.com/Software/Misc/Q_28338371.html#accepted-solution
0
Comment
Question by:deskchains
  • 5
  • 3
8 Comments
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 40573236
In addition to the question you showed above, here's another similar one:
http://www.experts-exchange.com/Software/Misc/Q_28337712.html

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
0
 

Author Comment

by:deskchains
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?
0
 
LVL 51

Accepted Solution

by:
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:

[ImPDF]

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

ImpdfPreviewOn=1

Change it to:

ImpdfPreviewOn=0

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:

[Others]
INI_Folder=%APPDATA%\IrfanView

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

c:\Users\<username>\AppData\Roaming\IrfanView\i_view32.ini

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:

Loop
{
  InputBox,Compression,Compression,

to:

  Break
}

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:

/tifc=%Compression%

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
0
 

Author Closing Comment

by:deskchains
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:
SecurityActive=1
SecurityLevel=1
SecurityModifyPwd=1
SecurityOpenPwd=0
SecurityNoPrint=0
SecurityNoModify=1
SecurityNoCopy=0
SecurityNoComment=1
 *********************
To:

SecurityActive=0
SecurityLevel=0
SecurityModifyPwd=0
SecurityOpenPwd=0
SecurityNoPrint=0
SecurityNoModify=0
SecurityNoCopy=0
SecurityNoComment=0

and the merging of the PDF goes like a snap.  Great Job and thanks so much
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:deskchains
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.
0
 
LVL 51

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
0
 
LVL 51

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?
0
 
LVL 51

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:

FileMove,%DestFolder%temp.pdf,%DestFolder%%FirstCharsCurrent%.pdf

to:

FileMove,%DestFolder%temp.pdf,%DestFolder%%FirstCharsCurrent%Rpt.pdf

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:

Loop
{
  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
    Exit
  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
    IfMsgBox,Cancel
      Exit
    Else
      Continue
  }
  Break
}

Open in new window


(2) Change this line:

FileMove,%DestFolder%temp.pdf,%DestFolder%%FirstCharsCurrent%.pdf

to this line:

FileMove,%DestFolder%temp.pdf,%DestFolder%%FirstCharsCurrent%%Suffix%.pdf

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

ExitApp

BadVarWin(FileChars)
{
  BadCharsWin:="<>:""/|\?*"
  FileCharsLen:=StrLen(FileChars)
  Loop %FileCharsLen%
  {
    FileCharsCheck:=SubStr(FileChars,A_Index,1)
    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
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now