Ik ben opzoek naar een manier om twee losse pdf files te combineren en dubbelzijdig te printen.
Combineren is eigenlijk niet nodig maar ik zie niet in hoe ze anders dubbelzijdig geprint kunnen worden.
Dit wil ik dan vanuit een macro in excel realiseren.
Ik heb dit via pdfcreator geprobeerd. Pdfcreator heeft zelf bij installatie een aantal voorbeeld scrips. Hieronder staat de code die ik hiervoor gevonden heb en een beetje aangepast.
De code werkt maar weet iemand;
Hoe te zorgen dat de verschillende pdf's hun oorspronkelijke formaat blijven behouden?
Hoe ik de gecombineerde pdf op papier geprint krijg met vba?
Is er wellicht een andere/eenvoudigere manier om dit probleem te benaderen (zonder pdfcreator)?
Ik loop hier al een paar weken over te denken en kom niet echt verder.
Alle hulp, suggesties en aanwijzingen zijn welkom en zeer gewaardeerd
Gr,
Jelmei
Sub bindPDF()
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim DefaultPrinter$
Dim bRestart As Boolean
Dim sFilenames(2) As String
sFilenames(1) = "C:\Users\MG\Desktop\Test\test1.pdf"
sFilenames(2) = "C:\Users\MG\Desktop\Test\test2.pdf"
'/// Change the output file name here! ///
sPDFName = "Combikaart"
'' stub here
sPDFPath = "C:\Users\MG\Desktop\Test\"
'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")
'Wait until all the print jobs have entered the queue
Do Until pdfjob.cCountOfPrintjobs = 2
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
Combineren is eigenlijk niet nodig maar ik zie niet in hoe ze anders dubbelzijdig geprint kunnen worden.
Dit wil ik dan vanuit een macro in excel realiseren.
Ik heb dit via pdfcreator geprobeerd. Pdfcreator heeft zelf bij installatie een aantal voorbeeld scrips. Hieronder staat de code die ik hiervoor gevonden heb en een beetje aangepast.
De code werkt maar weet iemand;
Hoe te zorgen dat de verschillende pdf's hun oorspronkelijke formaat blijven behouden?
Hoe ik de gecombineerde pdf op papier geprint krijg met vba?
Is er wellicht een andere/eenvoudigere manier om dit probleem te benaderen (zonder pdfcreator)?
Ik loop hier al een paar weken over te denken en kom niet echt verder.
Alle hulp, suggesties en aanwijzingen zijn welkom en zeer gewaardeerd
Gr,
Jelmei
Sub bindPDF()
Dim pdfjob As PDFCreator.clsPDFCreator
Dim sPDFName As String
Dim sPDFPath As String
Dim DefaultPrinter$
Dim bRestart As Boolean
Dim sFilenames(2) As String
sFilenames(1) = "C:\Users\MG\Desktop\Test\test1.pdf"
sFilenames(2) = "C:\Users\MG\Desktop\Test\test2.pdf"
'/// Change the output file name here! ///
sPDFName = "Combikaart"
'' stub here
sPDFPath = "C:\Users\MG\Desktop\Test\"
'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")
'Wait until all the print jobs have entered the queue
Do Until pdfjob.cCountOfPrintjobs = 2
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