Solved

Merge PDF based on filename prefix

Posted on 2015-01-27
8
172 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 52

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 52

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 52

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 52

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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

912 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

20 Experts available now in Live!

Get 1:1 Help Now