topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Friday December 13, 2024, 4:57 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: DONE: Using AHK and PDFTK to combine daily pdf's  (Read 8297 times)

schnarkle

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11
    • View Profile
    • Donate to Member
DONE: Using AHK and PDFTK to combine daily pdf's
« on: November 14, 2012, 05:40 PM »
Hello,

I need to come up with a way of combining daily extracted pdfs in the proper order but am having problems with the number of different publications.

Our naming convention is :

pub  date     section
--------------------  
MM_111412_A01.pdf
MM_111412_A02.pdf
MM_111412_B01.pdf
MC_111412_A01.pdf
WR_111412_A01.pdf

I can do this for one pub easily i.e.

Code: Autohotkey [Select]
  1. SetWorkingDir, %A_ScriptDir%
  2. pub = MM
  3.  
  4. dest = D:\DATA\archives\hot\
  5. formattime, date, MMddyy, MMddyy
  6.  
  7. filename1 = %pub%_%date%_*.pdf
  8.  
  9. ifexist %filename1%
  10. Runwait %comspec% /c pdftk %filename1% cat output %dest%EA_%date%.pdf

But with 7 different pubs, some of which may or may not appear on a daily basis, I am stuck.

Here's what I came up with but it is not getting every pub and some pages are repeating.  I am trying but am an amateur N00B :)
Also, the pub order is as seen top to bottom.

Code: Autohotkey [Select]
  1. SetWorkingDir, %A_ScriptDir%
  2. pub = MM
  3. pub2 = MC
  4. pub3 = FE
  5. pub4 = CS
  6. pub5 = RE
  7. pub6 = VL
  8. pub7 = WR
  9.  
  10. dest = D:\DATA\archives\hot\
  11. formattime, date, MMddyy, MMddyy
  12.  
  13. filename1 = %pub%_%date%_*.pdf
  14. filename2 = %pub2%_%date%_*.pdf
  15. filename3 = %pub3%_%date%_*.pdf
  16. filename4 = %pub4%_%date%_*.pdf
  17. filename5 = %pub5%_%date%_*.pdf
  18. filename6 = %pub6%_%date%_*.pdf
  19. filename7 = %pub7%_%date%_*.pdf
  20.  
  21. FileList =
  22. Loop, *_%date%_*.pdf
  23. {
  24.  FileList = %FileList%%A_LoopFileName%`n
  25.  
  26.  Runwait %comspec% /c pdftk %filename1% %A_LoopFileName% cat output MTR_%date%.pdf
  27. }
Can anyone help?

« Last Edit: November 14, 2012, 07:47 PM by skwire, Reason: Added code tags. Hope you don\'t mind. =] »

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: DONE: Using AHK and PDFTK to combine daily pdf's
« Reply #1 on: November 14, 2012, 08:00 PM »
I assume you're trying to do this in AHK?

you need 2 nested loops, something like this

pub = MM,MC,FE,CS,RE,VL,WR

loop, parse, pub, CSV
{
    Loop, %a_loopfield%_%date%_*.pdf
        Runwait %comspec% /c pdftk %filename1% %A_LoopFileName% cat output MTR_%date%.pdf
}



skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Using AHK and PDFTK to combine daily pdf's
« Reply #2 on: November 14, 2012, 08:26 PM »
You can pass multiple PDF filenames at one time to pdftk.  This should work:

Code: Autohotkey [Select]
  1. ; Environment.
  2.  
  3. ; Variables.
  4. FormatTime, myDate, A_Now, MMddyy ; Format today's date.
  5. myPubOrder := "MM,MC,FE,CS,RE,VL,WR"
  6.  
  7. ; Maintain publication order as per request.
  8. Loop, Parse, myPubOrder, `,
  9. {
  10.     ; Create a space-delimited list of PDF filenames.
  11.     Loop, % A_LoopField . "_" . myDate . "_*.pdf"
  12.     {
  13.         myString .= A_LoopFileName . " "
  14.     }
  15. }
  16. ; Pass full list of PDFs to pdftk and output to new file.
  17. RunWait %comspec% /c pdftk.exe %myString% cat output MTR_%myDate%.pdf

schnarkle

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11
    • View Profile
    • Donate to Member
Re: DONE: Using AHK and PDFTK to combine daily pdf's
« Reply #3 on: November 15, 2012, 10:36 AM »
Good grief you guys make it look so easy!

Thank you so much that was driving me nuts!

 :Thmbsup:

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: DONE: Using AHK and PDFTK to combine daily pdf's
« Reply #4 on: November 15, 2012, 11:03 AM »
Good grief you guys make it look so easy!
Thank you so much that was driving me nuts!

You're very welcome.  I'm glad we were able to help out.   :)  I'm going to mark this thread as done and move it.