Here is what I ended up with and it works quite well! Thanks for all your help.
Code: Select all
#SingleInstance,Force
Gui, Font, s14 underline, Calibri
Gui, Add, text, x10, Target File
Gui, Font, s8 Normal,
Gui, Add, edit, Disabled x10 y35 h25 w400 vFilePath, Select a File..
Gui, add, button, x410 y33 h28 w51 gLetterFile, Browse..
Gui, Font, s13.5 underline, Calibri
Gui, Add, text, x10, Processing Summary
Gui, Font, s10 normal, Calibri
Gui, Add, text, x11 y100, Start Page
Gui, Add, text, x96 y100, End Page
Gui, Add, text, x181 y100, Page Count
Gui, Add, text, x266 y100, Letters Processed
Gui, Add, Edit, x10 y115 w80 vS_Page
Gui, Add, Edit, x95 y115 w80 vE_Page
Gui, Add, Edit, x180 y115 w80 vP_Count
Gui, Add, Edit, x265 y115 w100 vL_Processed
Gui, Add, Button, x370 y114 gStart, Process
Gui, Show
return
LetterFile:
FileSelectFile, LetterFile, 1,, Select a PDF, PDF Document (*.pdf) ;Choose a PDF
SplitPath, LetterFile, SelectedFile
SplitPath, LetterFile,, dir
GuiControl, , FilePath, %LetterFile%
Gui, Submit
Gui, Show
return
Start:
XL := ComObjActive("Excel.Application")
PDDoc := ComObjCreate("AcroExch.PDDoc")
PDDoc.Open(LetterFile)
;PDDoc.OpenAVDoc("") ; causes display
;Msgbox, % PDDoc.GetNumPages()
PDDoc2 := ComObjCreate("AcroExch.PDDoc")
PDDoc2.Create() ;create the second document to insert pages into
;[~First loop to extract pages into own files~]
number = 0 ;start at 0 so cell offset increment starts at 1 in loop.
Loop
{
NewFile:
number++ ;incriment by 1
FirstPage := XL.ActiveCell.Offset(-number,0).Value ;get first page number
LastPage := XL.ActiveCell.Offset(-number,1).Value ;get last page number to right of cell point
Count := XL.ActiveCell.Offset(-number,2).Value
GuiControl,, S_Page, %FirstPage%
GuiControl,, E_Page, %LastPage%
GuiControl,, P_Count, %Count%
GuiControl,, L_Processed, %number%
If (Count = "Count Page")
{
NewFileName2 = %dir%\EXTRACTS %SelectedFile% - %Count% Page Letters.pdf
PDDoc2.Save(1, NewFileName2)
break ; stop when we hit the end
}
If (FirstPage = "") ;if FirstPage is null, break out of the loop.
{
;create new instance and file for next group and continue
;PDDoc2.OpenAVDoc("") ; causes display
If (LastCount = "")
{
NewFileName2 = %dir%\EXTRACTS %SelectedFile% - %Count% Page Letters.pdf
PDDoc2.Save(1, NewFileName2)
msgbox, New File: %NewFileName2%
}
Else
{
NewFileName = %dir%\EXTRACTS %SelectedFile% - %LastCount% Page Letters.pdf
PDDoc2.Save(1, NewFileName)
msgbox, New File: %NewFileName%
}
PDDoc2.Close()
verify := number + 1
;msgbox, % verify
VerifyNextCount := XL.ActiveCell.Offset(-verify,2).Value
If (VerifyNextCount != "Count Page")
{
msgbox, Next New File Pages: %VerifyNextCount%
PDDoc2.Create() ;create a new instance
}
GoTo, NewFile
}
PDDoc2.InsertPages(-1, PDDoc, firstPage, Count, 0) ; index-0, add at beginning from PDDoc the second to third pages without bookmarks
LastCount = %Count%
}
PDDoc.OpenAVDoc("") ; causes display
PDDoc2.OpenAVDoc("") ; causes display
msgbox, done
;PDDoc.Save(1, LetterFile)
;PDDoc2.Save(1, NewFileName)
PDDoc.Close()
PDDoc2.Close()
ObjRelease(PPDoc)
;Written by Vh_
;Credit - Thanks to FanaticGuru and AutoHotkey Community for assistance! May 2018
Excel Example below. Column A and B are page ranges, start and end. C is page count. I have them split into regions so when it his a blank cell (like 4 and 7), make a new file.