#### 15.1.5 Producing PDF automatically via Word

Starting with Word 2007, Microsoft Word can output PDF with no added tools. This means that you can run your entire DITA2Go conversion, from ditamap to PDF, as one step, using a Word macro to get from RTF to PDF. For earlier versions of Word, you can use Adobe PDF as your printer if you have Adobe Acrobat (not just Reader). Or, there are dozens of other PDF makers, many of them free.

Note: A defect in the 64-bit version of Office 2010 might cause Word to crash when you try to create a PDF from your DITA2Go Word output. The remedy is to use the 32-bit version of Word 2010, even if you are on a 64-bit Windows 7 system.

What you need is a Word macro that will do the following upon loading an RTF file:

1. Update fields
2. Generate the index, if you included index terms (see §15.10.2 Including index terms in Word)
3. Save as .doc
4. Generate a PDF file, with active links (except from index entries).

PDF macro for Word 2007

The following Word macro is designed for Word 2007:

    Sub LoadD2gRtfFile()
    '
    ' LoadD2Grtf2007 Macro
    ' Macro recorded 5/31/2010 by Omni Systems
    '
       Dim nameStr As String
       Selection.WholeStory
       Selection.Fields.Update
       nameStr = Replace(ActiveDocument.FullName, ".rtf", ".doc")
       ActiveDocument.SaveAs FileFormat:=wdFormatDocument, _
          FileName:=nameStr, LockComments:=False
       nameStr = Replace(ActiveDocument.FullName, ".doc", ".pdf")
       ActiveDocument.ExportAsFixedFormat OutputFileName:=nameStr, _
          ExportFormat:=wdExportFormatPDF, _
          OptimizeFor:=wdExportOptimizeForPrint, _
          Range:=wdExportAllDocument, From:=1, To:=1, _
          Item:=wdExportDocumentContent, KeepIRM:=True, _
          CreateBookmarks:=wdExportCreateNoBookmarks, _
          DocStructureTags:=True, BitmapMissingFonts:=True, _
          UseISO19005_1:=False
       Selection.StartOf
    End Sub

This particular macro works in Word 2007, provided you uncheck the “rely on system fonts only” option in Adobe PDF printing preferences. You might have to modify the macro for other versions of Word. Try to run it from within Word after you load the RTF and save it as .doc (or .docx). See if it works then. Also, make sure the name of the macro is correct. Depending on which version of Word you use, the resulting PDF file will have active links, except for index entries.

Settings required for PDF production

For automatic PDF production you must also include the following settings in your DITA2Go project configuration file:

    [Setup]
    ; To get the correct extension after Word saves as .doc:
    FileSuffix=.doc

    [WordOptions]
    ; To get active links, you must target Word 2007 or a later version:
    Word2007 = Yes
    ; To run the macro from the Project Manager:
    ViewOutputCommand = path/to/winword.exe /mLoadD2gRtfFile

PDF from the Project Manager

When you click View Output on the DITA2Go Project Manager Run Project tab, the Project Manager loads your RTF output file in Word. The macro runs, producing a PDF with the same base name as your Word RTF file, and extension .pdf. See §15.1.6 Launching Word from the DITA2Go Project Manager.

PDF from the command line

To produce PDF via Word from the command line:

    dcl -f rtf -o .doc ..\mymap.bookmap "path/to/winword.exe" /mLoadD2gRtfFile mymap.doc

This command must be all on one line, even if it does not look that way here. See §2.7 Converting documents from the command line

Previous Topic: 15.1.4 Including or excluding contents and index for RTF output

Next Topic: 15.1.6 Launching Word from the DITA2Go Project Manager

Parent Topic: 15.1 Setting up a print RTF project

Sibling Topics:

15.1.1 Specifying output file extension

15.1.2 Specifying the default output language and code page

15.1.3 Constraining the number of bookmarks in Word

15.1.4 Including or excluding contents and index for RTF output

15.1.6 Launching Word from the DITA2Go Project Manager

15.1.7 Importing a Word template