9 Replies Latest reply on Aug 24, 2011 4:18 PM by MannyS18

    Creating PDF via Word Macro using Adobe Acrobat 9 Pro

    shaww01

      I've been trying to create a macro for Word documents that will write the document out as a PDF and named as C:\temp\temp.pd. My macro to date is below, but everything I've tried so far results in a .prn file, though it is named temp.pdf. Trying to record the Macro using toolbar buttons or dropdowns yields a macro with no code. Any suggestions?

       

      Sub WritePdfFile()
      '
      ' WritePdfFile Macro
      '
          Windows(1).Activate
          ActivePrinter = "Acrobat PDFWriter"
          Application.PrintOut FileName:="", OutputFileName:="C:\temp\temp.pdf", Range:=wdPrintAllDocument, Item:= _
              wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
              Collate:=True, Background:=True, PrintToFile:=False

        • 1. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
          Bernd Alheit Adobe Community Professional & MVP
              ActivePrinter = "Acrobat PDFWriter"

          Adobe Acrobat 9 comes with a printer named 'Adobe PDF'.

          • 2. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
            shaww01 Level 1

            Thank you Bernd.

             

            I think I tried his before, but revisited it based on your suggestion, using ActivePrinter = "Adobe PDF" . However, the results are the same. The file created is a prn file.  I've seen some references to a MS Word 'PDF Maker' plug-in that perhaps should be used, but this does not seem necessary to me. This is because, with the same document opened in Word, I can select the 'Convert to Adobe PDF' toolbar button and this creates a temp.pdf file as I need it. The challenge seems to be to get the same behavior through the use of a Macro.

            • 3. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
              Bernd Alheit Adobe Community Professional & MVP

              The file created is a prn file.

              Is this a Postscript file?

              • 4. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
                shaww01 Level 1

                Yes. It is a file formatted to be sent to a printer.

                • 5. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
                  Bernd Alheit Adobe Community Professional & MVP

                  You can use Acrobat Distiller to convert Postscript to PDF.

                  • 6. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
                    shaww01 Level 1

                    Hmm. Well, I need to accomplish this via a macro. Does it make sense to use Adobe PDF and then somehow call Distiller with that ouput to create a PDF? What I'd like to hook into or emulate is the button on the tool bar (labled Convert to Adobe PDF). This tool option comes from customizing and selecting the 'Acrobat PDFMaker 9.0' toolbar. If I click on that I can create a pdf and save it as temp.pdf. That's what I'm trying to do via a macro.

                    • 7. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
                      gkaiseril MVP & Adobe Community Professional

                      Is the file you are editing a PostScript file? The file type must be ".PS" and be internally formatted to comply with the PostScript Language Reference.

                       

                      If it is a true Post Script file, you can save the file to the "IN" directory of a distiller watched folder and if distiller is open, that or any other file placed in that special folder will be processed  by Acrobat Distiller. If the contents of the file has all the correct formatting and syntax, a PDF file will be placed in the special "OUT" folder. If it is not a PS file or has errors, no PDF file will be produced.

                       

                      Here is a sample PS file you can distill:

                       

                      %!PS
                      %!Created by Fi, 26 Jun 1996
                      % a4: 595 x 842
                      /color false def % say /color true def, if you want colors
                      /width 595 def
                      /height 842 def
                      /in { 72 mul } bind def
                      /size { 1.2 in } bind def
                      /sqrt2 1.41421356237310 def
                      /limit 1.2 def
                      /r 1 def /g 0 def /b 0 def
                      /box { % stack: size
                        newpath
                        0 0 moveto
                        dup 0 rlineto
                        dup 0 exch rlineto
                        dup 0.5 mul dup dup -1 mul exch rlineto
                        -1 mul dup rlineto
                        closepath
                        color
                        { r g b setrgbcolor fill r g b /g exch def /r exch def /b exch def }
                        { stroke }
                        ifelse % stack: size
                        dup
                        limit gt {
                          gsave
                            dup dup sqrt2 div exch 0 exch translate 45 rotate box
                          grestore
                          gsave
                            dup sqrt2 div exch 2 div dup 3 mul translate 315 rotate box
                          grestore
                          } { pop } ifelse
                        } def
                      1 1 scale
                      width 1.5 in sub height 2 div size 2 div sub translate
                      90 rotate
                      size box
                      showpage

                      • 8. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
                        shaww01 Level 1

                        The file I am working with is a .doc file. It gets changed to a prn file when I execute the Macro I currently have defined - in an attempt to save it is C:\temp\temp.pdf.  The resulting file gets named C:\temp\temp.pd, but it is in actuality a prn file - can't be opened by Adobe Acrobat.  The suggestion above of subsequently passingthe prn file off to a Distiller directory to generate a pdf probably will not work because of timing issues. Here's some more background on why and what I am trying to do:

                         

                        This activity is happening in a program running in a batch mode.  This program is using OLE to open Word documents, add watersmarks and other details, then save the changed Word doc as a pdf to c:\temp\temp.pdf.  The program then, expecting the temp file to be where it is, sends temp.pdf to a Document Management System, changing the name in the process to something more meaningful.  Additionally, in some cases, an additional Word doc is created on the fly which must also be saved as C:\temp\temp.pdf and is immediately thereafter procesed in a similar way - sent to a Document Management System.

                         

                        The above work just fine when we used Acrobat 5.0 with PDF Writer 5.0.  The fact that PDF Writer would always write its output to C:\temp\temp.pdf (as an actual PDF file) was controlled through a registry setting (PDFFileName).  WIth Acrobat 9 Pro, this registry setting no longer works as it did in 5.0.  The switch to Adobe Acrobat 9 Pro is necessitated by the need to process documents with Chinese characters.  I've seen some references to PDF Maker and perhaps this is a product that needs to be added to this process, but I can't find complete information on this product.

                        • 9. Re: Creating PDF via Word Macro using Adobe Acrobat 9 Pro
                          MannyS18

                          I have Word 2007 and Acrobat Pro 9, but this also worked with the last setup of Word 2002 and Acrobat Pro 7.

                          Go to your printer folder

                          Right click on "Adobe PDF"

                          Select "Printing preferences"

                          Under the tab "Adobe PDF Settings"

                          Click "Browse..." next to "Adobe PDF Output Folder"

                          Select the directory you want (In your case "C:\temp\")

                          Click "Apply" and then put the code below into your VBA program

                           

                              stdPrinter = ActivePrinter
                              ActivePrinter = "Adobe PDF"
                              Application.PrintOut
                              ActivePrinter = stdPrinter