Combining Microsoft Office documents to a PDF through COM-automation

I've realized that a lot of postings exist to the question how to combine files to one PDF using COM automation.

Some help is provided in the COM folder of PDFCreator through samples; however, the help file is not very clear about the sense of the commands. I've realized that in a first step you must use PDFCreator manually to see which commands are necessary, so that in a second step you can look up the commands in the object model.

My solution works in a VS 2010 COM add-in for Word, but can easily be adopted to other circumstances. Hope it helps somebody.

==============  Code =============================

      Private Sub AdxBSBtn_PrintInvoiceToPDFCreator_OnClick(ByVal sender As Object, ByVal control As AddinExpress.MSO.IRibbonControl) Handles AdxBSBtn_PrintInvoiceToPDFCreator.OnClick

        Dim docCurr As Word.Document
        Dim objFF As Word.FormField
        Dim objWordApp As Word.Application = WordApp


        If WordApp.Documents.Count = 0 Then GoTo PROC_EXIT

        'Save current active printer, and setup PDFCreator as active printer
        Dim strActivePrinter = WordApp.ActivePrinter
        WordApp.ActivePrinter = "PDFCreator"

        'Create instance of PDFCreator
        PDFCreator1 = New PDFCreator.clsPDFCreator

        'Get instance of current Word document
        docCurr = WordApp.ActiveDocument

        Try
            'FIRST PRINTOUT ACTION
            With PDFCreator1
                'Start PDFCreator
                .cStart("/NoProcessingAtStartup")
                'Stop processing = click the "Stop printer" button in PDFCreator print monitor.
                .cPrinterStop = True
                'Set options. To have more information about the options,
                'open PDFCreator Print Manager and look up the "Printer, Settings" page.
                .cOption("UseAutosave") = 1
                .cOption("UseAutosaveDirectory") = 1
                .cOption("AutosaveDirectory") = docCurr.Path
                'We assume that the document was already saved...
                .cOption("AutosaveFilename") = docCurr.Name
                .cOption("AutosaveFormat") = 0             ' 0 = PDF
                'Hide the options dialog during processing:
                .cShowOptionsDialog(False)

                'Print entire Word document
                docCurr.PrintOut(Background:=False)

                'Send thread to sleep a second and allow PDFCreator to process,
                'equals the "DoEvents" command in VB6 and VBA.
                Threading.Thread.Sleep(1000)
            End With
            'Change content in the Word document/ Prepare for 2nd printout:
            objFF = docCurr.FormFields.Item("txt_PrintNotice")
            objFF.TextInput.Default = "DUPLICATE"
            objFF.Range.Fields.Update()

            'At this stage, you may open the PDFCreator print monitor and you'll see
            'that the first file is processed and waiting

            With PDFCreator1
                'Just print again the entire document:
                docCurr.PrintOut(Background:=False)
                Threading.Thread.Sleep(1000)

                'In the print monitor we have now two files. Manually, we have to press
                'Ctrl+A to combine the to one file, here we use :
                .cCombineAll()
                'And to process the combined files, start the printer again:
                .cPrinterStop = False
                Threading.Thread.Sleep(1000)

            End With
            'Clean up the Word document
            objFF.TextInput.Default = ""
            objFF.Range.Fields.Update()

            'Reset the formerly used printer
            WordApp.ActivePrinter = strActivePrinter

            'Destroy the PDFCreator object
            PDFCreator1 = Nothing

        Catch ex As Exception
            MessageBox.Show("Error: " & ex.Message)

        End Try

PROC_EXIT:

    End Sub