DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

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

schnarkle

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11
DONE: Using AHK and PDFTK to combine daily pdf's
« on: November 14, 2012, 11: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)
SetWorkingDir, %A_ScriptDir%
pub = MM

dest = D:\DATA\archives\hot\
formattime, date, MMddyy, MMddyy
 
filename1 = %pub%_%date%_*.pdf

ifexist %filename1%
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)
SetWorkingDir, %A_ScriptDir%
pub = MM
pub2 = MC
pub3 = FE
pub4 = CS
pub5 = RE
pub6 = VL
pub7 = WR

dest = D:\DATA\archives\hot\
formattime, date, MMddyy, MMddyy
 
filename1 = %pub%_%date%_*.pdf
filename2 = %pub2%_%date%_*.pdf
filename3 = %pub3%_%date%_*.pdf
filename4 = %pub4%_%date%_*.pdf
filename5 = %pub5%_%date%_*.pdf
filename6 = %pub6%_%date%_*.pdf
filename7 = %pub7%_%date%_*.pdf

FileList = 
Loop, *_%date%_*.pdf
{
 FileList = %FileList%%A_LoopFileName%`n

 Runwait %comspec% /c pdftk %filename1% %A_LoopFileName% cat output MTR_%date%.pdf 
}
Can anyone help?

« Last Edit: November 15, 2012, 01:47 AM by skwire »

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,840
    • Coding Snacks
Re: DONE: Using AHK and PDFTK to combine daily pdf's
« Reply #1 on: November 15, 2012, 02:00 AM »
I assume you're trying to do this in AHK?

you need 2 nested loops, something like this

Code
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 
}

Alcohol is photoshop, bottled
Askhole - someone who ask for advice, then ignores it
"Look wise, say nothing, and grunt. Speech was given to conceal thought" - Sir William Osler

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Using AHK and PDFTK to combine daily pdf's
« Reply #2 on: November 15, 2012, 02:26 AM »
You can pass multiple PDF filenames at one time to pdftk.  This should work:

Code: (autohotkey)
; Environment.
SetWorkingDir, % A_ScriptDir

; Variables.
FormatTime, myDate, A_Now, MMddyy ; Format today's date.
myPubOrder := "MM,MC,FE,CS,RE,VL,WR"
 
; Maintain publication order as per request.
Loop, Parse, myPubOrder, `,
{
    ; Create a space-delimited list of PDF filenames.
    Loop, % A_LoopField . "_" . myDate . "_*.pdf"
    {
        myString .= A_LoopFileName . " "
    }
}
; Pass full list of PDFs to pdftk and output to new file.
RunWait %comspec% /c pdftk.exe %myString% cat output MTR_%myDate%.pdf

schnarkle

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

Thank you so much that was driving me nuts!

:Thmbsup:

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: DONE: Using AHK and PDFTK to combine daily pdf's
« Reply #4 on: November 15, 2012, 05:03 PM »
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.

Original address: https://www.donationcoder.com/forum/index.php?topic=32871.0