Solved

Merge PDF based on filename prefix

Posted on 2015-01-27
8
204 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
[X]
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
8 Comments
 
LVL 54

Expert Comment

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

Accepted Solution

by:
Joe Winograd, EE MVE 2015&2016 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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
 

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 54

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

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

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:

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

691 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