Binding multiple pdfs into one pdf with or without PDF architect

Webrohm

New member
Joined
Jul 7, 2012
Messages
5
Reaction score
0
Points
0
Location
New Zealand
I have successfully generated 500 unique excel files to pdf using PDFCreator and Ken's brilliant PrinttoPDF code.
Now I want to bind a cover document (cover.pdf) and a back page (back.pdf) to each of the 500 unique files. This all seems to hinge on getting them in the print queue and in reverse order.
My question is can I do this via VBA with the PDFCreator COM as PDF Architect doesnt appear to have one?
 
Hi Webrohm...

there are some VB-Script samples located in the folder Your_Install_Path\PDF Creator\COM\Windows Scripting Host\VBScripts.
The file CombineJobs.vbs shows how to combine two PDF's. I think, this code could be relatively easily adapted to VBA.
Hope this helps.

Regards :)
 
Hi Webrohm...

Ok, I can try. Where are located the PDF's? All in the same folder?

Regards :)
 
Yes, all in same folder.
pdf 1 = cover.pdf
pdf 2 = 1....500.pdf
pdf3 = back.pdf
so pdf1 and pdf3 need to combine with 500 uniquely numbered pdfs in the order indicated.
The pdfs have been produced from different applications so all I am trying to do is bind the completed pdfs
 
Just a hack on Ken's great script.
bindPDF is called from a loop passing all the files in a dir (fnamein) and putting them out with the name fnameout.
The key came from a pdfforge.org post and it was to associate pdf files with FoxIT (foxitsoftware.com - free version). Had to play around with the wait time as you can see (there must be a better way to do this?)

Sub bindPDF(fnamein$, fnameout$)

Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim DefaultPrinter$
Dim bRestart As Boolean

Dim sFilenames(3) As String

sFilenames(1) = "C:\Documents and Settings\me\Desktop\quintiles\pdf\cover.pdf"
sFilenames(2) = "C:\Documents and Settings\me\Desktop\quintiles\pdf\" & fnamein
sFilenames(3) = "C:\Documents and Settings\me\Desktop\quintiles\pdf\back.pdf"

'/// Change the output file name here! ///
sPDFName = fnameout

'' stub here
sPDFPath = "C:\Documents and Settings\me\Desktop\quintiles\pdfout\"

'Activate error handling and turn off screen updates
On Error GoTo EarlyExit
' Application.ScreenUpdating = False
Set pdfjob = New PDFCreator.clsPDFCreator

'Check if PDFCreator is already running and attempt to kill the process if so
Do
bRestart = False
Set pdfjob = New PDFCreator.clsPDFCreator
If pdfjob.cStart("/NoProcessingAtStartup") = False Then
'PDF Creator is already running. Kill the existing process
Shell "taskkill /f /im PDFCreator.exe", vbHide
DoEvents
Set pdfjob = Nothing
bRestart = True
End If
Loop Until bRestart = False

'Assign settings for PDF job
With pdfjob
.cOption("UseAutosave") = 1
.cOption("UseAutosaveDirectory") = 1
.cOption("AutosaveDirectory") = sPDFPath
.cOption("AutosaveFilename") = sPDFName
.cOption("AutosaveFormat") = 0 ' 0 = PDF
DefaultPrinter = .cDefaultPrinter
.cDefaultPrinter = "PDFCreator"
.cClearCache
End With

'Delete the PDF if it already exists
If Dir(sPDFPath & sPDFName) = sPDFName Then Kill (sPDFPath & sPDFName)

'Print the document to PDF
With pdfjob
' change this filename each loop

.cPrintFile (sFilenames(1))
Application.Wait Now + TimeValue("0:0:2")
.cPrintFile (sFilenames(2))
Application.Wait Now + TimeValue("0:0:2")
.cPrintFile (sFilenames(3))
Application.Wait Now + TimeValue("0:0:2")

'Wait until all the print jobs have entered the queue
Do Until pdfjob.cCountOfPrintjobs = 3
DoEvents
Loop
.cCombineAll
.cPrinterStop = False

End With
'Wait until the PDF file shows up then release the objects
Do Until pdfjob.cCountOfPrintjobs = 0
DoEvents
Loop

'Wait a bit longer for PDF Creator to finish
Application.Wait Now + TimeValue("0:0:2")

'reset original Windows' default printer
pdfjob.cDefaultPrinter = DefaultPrinter
pdfjob.cClose

Cleanup:
'Release objects and terminate PDFCreator
Set pdfjob = Nothing
Shell "taskkill /f /im PDFCreator.exe", vbHide
On Error GoTo 0
'Application.ScreenUpdating = True
Exit Sub

EarlyExit:
'Inform user of error, and go to cleanup section
MsgBox "There was an error encountered. PDFCreator has" & vbCrLf & _
"has been terminated on file " & sPDFName & " in bind. Please try again.", _
vbCritical + vbOKOnly, "Error"
Resume Cleanup

End Sub
 
Need excel format for this program, I'm mean I need template
 
Back
Top