15 Replies Latest reply on Apr 19, 2017 7:01 AM by Karl Heinz Kremer

    How do I invoke Word PDFMaker from a macro?

    Level 1
      Hi,

      I need to automate creating PDF's from Word with hyperlink fields converted precisely. The Adobe toolbar "Convert to Adobe PDF" button does exactly what I need. How do I invoke this type of conversion programmaticially, e.g. from a Word macro? Can anyone point me to a SDK document that discusses this?

      (BTW, printing the document to the "Adobe PDF" printer will not work. I need the exact functionality of the toolbar button).
        • 1. Re: How do I invoke Word PDFMaker from a macro?
          Level 1
          I have found enough information to script the conversion, but not the actual documentation. I'd still appreciate any pointers anyone could give me to the documentation for the AdobePDFMakerForOffice.PDFMaker object.

          It would be pretty peculiar for this not to be documented since as far as I can tell, this is the only way to create PDF files from Word documents with functional intra- and inter-document hyperlinks. If there is a better, documented way please let me know by responding to this note!

          In any case, since I haven't seen this explained anywhere it might be useful to post some notes here. To script a conversion that doesn't require user intervention, get a reference to the PDFMaker add-in object from Word. From that, use the GetCurrentConversionSettings (or GetDefaultConversionSettings) method to get an ISetting object. Set property OutputPDFFilename to the desired PDF filename, and property PromptForPDFFilename to False. After making any other desired setting changes, use the PDFmaker object's CreatePDFEx property to perform the conversion.

          Here is a sample routine in Word VBA. Before you can run it, you must open the Word macro editor and using Tools > References, add a reference to your copy of AcrobatPDFMakerForOffice.tlb, in e.g. \Program Files\Adobe\Acrobat 8.0\PDFMaker\Office.

          >
          ' ----------------------------------------------------
          ' ConvertToPDFWithLinks - convert the current document
          ' to a PDF file, in the same folder as the document
          ' ----------------------------------------------------

          Sub ConvertToPDFWithLinks()
          Dim pdfname, i, a
          Dim pmkr As AdobePDFMakerForOffice.PDFMaker
          Dim stng As AdobePDFMakerForOffice.ISettings

          If Not ActiveDocument.Saved Then
          MsgBox "You must save the document before converting it to PDF", vbOKOnly, ""
          Exit Sub
          End If

          Set pmkr = Nothing ' locate PDFMaker object
          For Each a In Application.COMAddIns
          If InStr(UCase(a.Description), "PDFMAKER") > 0 Then
          Set pmkr = a.Object
          Exit For
          End If
          Next
          If pmkr Is Nothing Then
          MsgBox "Cannot Find PDFMaker add-in", vbOKOnly, ""
          Exit Sub
          End If

          pdfname = ActiveDocument.FullName ' construct output name
          i = InStrRev(pdfname, ".")
          pdfname = IIf(i = 0, pdfname, Left(pdfname, i - 1)) & ".pdf"

          ' delete PDF file if it exists
          If Dir(pdfname) <> "" Then Kill pdfname

          pmkr.GetCurrentConversionSettings stng
          stng.AddBookmarks = True ' make desired settings
          stng.AddLinks = True
          stng.AddTags = True
          stng.ConvertAllPages = True
          stng.CreateFootnoteLinks = True
          stng.CreateXrefLinks = True
          stng.OutputPDFFileName = pdfname
          stng.PromptForPDFFilename = False
          stng.ShouldShowProgressDialog = True
          stng.ViewPDFFile = False

          pmkr.CreatePDFEx stng, 0 ' perform conversion

          If Dir(pdfname) = "" then ' see if conversion failed
          MsgBox "Could not create " & pdfname, vbOKOnly, "Conversion failed"
          End If
          End Sub

          ' ----------------------------------------------------

          The steps of deleting the pdf file if it exists before converting and checking for the file after conversion are necessary. If the output file cannot be created (permissions, read-only, open etc) CreatePDFEx does not throw an error. It's better to find out.

          Note that Intellisense and the object browser can show you all of the available properties and methods of pmkr and stng. Here's the list, though I can't guarantee its accuracy -- I might have mistyped:

          PDFMaker methods:
          CreatePDF (retval as Long)
          CreatePDFEx (settings as AdobePDFMakerForOffice.ISettings, retval as Long)
          GetCurrentConversionSettings (byref settings as AdobePDFMakerForOffice.ISettings)
          GetDefaultConversionSettings (byref settings as AdobePDFMakerForOffice.ISettings)

          ISettings properties: (all Boolean except as noted)
          AddBookmarks
          AddLinks
          AddTags
          AdvancedTagging
          AllowBleeds
          AlwaysFlattenLayers
          AttachSourceFile
          ConversionRoute
          ConvertAllPages
          ConvertHiddenSlides
          ConvertMultimedia
          ConvertSpeakerNotes
          CreateDocInfo
          CreateFootnoteLinks
          CreateLayers
          CreateMetadata
          CreateTextNodes
          CreateThreads
          CreateXrefLinks
          FitToOnePage
          InvokedFromFeat
          IsAutomation
          IsConversionSilent
          JobOptions as String
          LayoutBasedOnPrinterSettings
          OpenLayerPane
          OutputPDFFileName as String
          PDFACompliance
          PreserveSpotColor
          PreserveTransparency
          PrintActiveSheetOnly
          PrintBleedMarks
          PrintCropMarks
          PromptForPDFFilename
          PromptForSheetSelection
          Reserved as Long
          SaveAnimations
          SaveSlideShowTransitions
          SecuritySettings as Object
          SendForReview
          SendViaEmail
          ShouldShowProgressDialog
          ViewPDFFile

          ISettings methods:
          GetConversionRange (byref Range)
          SetConversionRange (Range)
          • 2. Re: How do I invoke Word PDFMaker from a macro?
            Level 1
            It might not be a wise thing to explore.
            http://support.adobe.com/devsup/devsup.nsf/docs/52841.htm
            • 3. Re: How do I invoke Word PDFMaker from a macro?
              chipcanty Level 1

              Sorry to kvetch, but do I understand correctly that Adobe removed this feature from Acrobat by declaring it unsupported.  For years I've been able to generate documents programmatically and store them as PDFs, with hyperlinks intact, with "Application.Run MacroName:='AdobePDFMaker.AutoExec.ConvertToPDF'."  Now this capability just disappears?  I would never have upgraded from Acrobat 6 had I known this.

              • 4. Re: How do I invoke Word PDFMaker from a macro?
                Bernd Alheit Adobe Community Professional & MVP

                These feature wasn't supported.

                • 5. Re: How do I invoke Word PDFMaker from a macro?
                  chipcanty Level 1

                  Hmm.  I can split hairs, too, so maybe the use of this macro by customers was never officially sanctioned or "supported" by Adobe.  But Adobe itself created the ConvertToPDF macro, and shipped it and installed it on customer machines as part of Acrobat over several releases.  In that context, to suddenly disable this function and say it was never supported seems a little misleading, no?

                  • 6. Re: How do I invoke Word PDFMaker from a macro?
                    slaycock Level 1

                    I came across the above macro only recently (Nov 2013).  I can confirm that it works with Acrobat XI. I now have a nice macro that recursively scans a set of subdirectories and converts all word documents meeting my specific naming criteria to pdf.  Definitely a happy bunny so thanks to Brian.

                    • 7. Re: How do I invoke Word PDFMaker from a macro?
                      Humiro Level 1

                      This code works great. The only issue I am having is clearing up the objects. I run a loop that uses this code and have several acrodist.exe running in the background. Is there a way to clean up the pdfmaker objects to successfuly close acrodist.exe after each iteration? I have tried releasecomobjects and setting the objects to nothing but that has not worked for me.

                      • 8. Re: How do I invoke Word PDFMaker from a macro?
                        gkaiseril MVP & Adobe Community Professional

                        Just try to remember the Acrobat add-in macro for MS Office is subject to Microsoft changes to MS Office and Adobe's updating to fix bugs and react to Microsoft's changing their products. What macros worked in MS Office 95 no longer work in MS Office 2010 because MS has changed the scripting language at least once. Also there is no requirement that Adobe keeps the same macro name for different versions of MS Office. Adobe has even changed the name of the executable exe file for Acrobat.

                        • 9. Re: How do I invoke Word PDFMaker from a macro?
                          sijpie Level 1

                          Humiro, before the sub ends you need to set the adobe objects to nothing:

                          Set pmkr = nothing

                          Set stng = nothing

                           

                          that should do the trick

                          • 10. Re: How do I invoke Word PDFMaker from a macro?
                            Miles29198932

                            I realize this is a fairly old post, but it turned out to be exactly what I was looking for. I'd like to say thank you for putting together this sample as it got me closer to where I need to be very quickly!

                             

                            Now, I do have one question. Out of the box, the sample Sub provided works, but I am having a problem where as soon as pmkr.CreatePDFEx is called, VBA execution is halted, and macros within the document are disabled. (So although PDF Maker runs, the VBA can't pick back up afterwards.) Is anyone familiar with why this might be happening, or if there's a fix for it? Thanks!

                            • 11. Re: How do I invoke Word PDFMaker from a macro?
                              Test Screen Name Most Valuable Participant

                              In case you missed it: it is and remains unsupported. As such it's undocumented and likely to change or vanish. So, happy it works for you, but don't make any promises about the future. For enterprise server use look at LiveCycle PDF Generator.

                              • 12. Re: How do I invoke Word PDFMaker from a macro?
                                Miles29198932 Level 1

                                Caught that, yep! The reason I ask is that my current workplace has a process set in place where Word documents need to be processed with PDF Maker (in order to retain relative file links) and I was looking at a quick way to automate it. I was hoping that this would work as a temporary method until a better process can be adopted, but still haven't been able to get it to continue macro execution after invoking PDF Maker.

                                • 13. Re: How do I invoke Word PDFMaker from a macro?
                                  michaelm58012143 Level 1

                                  Thank you for your post.  I have numerous (over 1000) PDFs that need to be regenerated from DOCXs after the documents are modified.  These documents are located over many folders.

                                   

                                  I am running Win 7 Pro, Word 2010 and Acrobat XI Standard.  Like the previous poster, I have been unable to successfully execute pmkr.CreatePDFEx, but pmkr.CreatePDF works just fine.  I believe the latter uses whatever conversion profile is selected in the preferences for PDFMaker for Word, which I have set to not prompt for the output PDF name (outputs to the same base name as the DOCX file).  This will save me an amazing amount of time.

                                   

                                  If I could figure out how to make Distiller work for this task, I would attempt that.  I have been unable to find documentation to interface with Distiller, at least with Acrobat XI Standard.  The ability to right-click on a DOCX and select "Convert to Adobe PDF" via Windows context menu would suffice if I could make that work in batch mode.  Again, I think this is a feature only available in the Pro versions of Acrobat.

                                  • 14. Re: How do I invoke Word PDFMaker from a macro?
                                    Test Screen Name Most Valuable Participant

                                    All supported interfaces are described in the Acrobat SDK. Including Distiller. But Distiller has only one job: converting PostScript to PDF. It doesn't read Word documents. It would read PostScript generated by printing to file, but when you use PDFMaker it does not use printing, or PostScript, or Distiller.

                                    • 15. Re: How do I invoke Word PDFMaker from a macro?
                                      Karl Heinz Kremer Adobe Community Professional

                                      michaelm58012143  wrote

                                       

                                      If I could figure out how to make Distiller work for this task, I would attempt that.  I have been unable to find documentation to interface with Distiller, at least with Acrobat XI Standard.  The ability to right-click on a DOCX and select "Convert to Adobe PDF" via Windows context menu would suffice if I could make that work in batch mode.  Again, I think this is a feature only available in the Pro versions of Acrobat.

                                      I can help you with this part: As was explained by TSN, Distiller by itself does not help you with converting from MS Word to PDF, but when you use the "Adobe PDF" printer, the MS Word document is actually converted to PostScript and then passed to Distiller in order to convert it to PDF. The only problem is that in order to automate this, you need to be able to "tell" Distiller what filename to use for the output file. How this is done is documented in the Acrobat SDK: Acrobat DC SDK Documentation

                                       

                                      You would have to automate MS Word to open a document, and then print it to the "Adobe PDF" printer (after you set the registry keys required by this solution). A few years ago, I wrote a tutorial about how to do that in VBS: Prevent the Save Dialog when Printing to the Adobe PDF Printer