8

I'm looking for a way to be able to add some options to the Right Click Context menu in Windows 7. I really don't have much experience in programming much but I am very eager and willing to learn.

Specifically I'd like to be able to Right Click a word document and have it convert or save as a .PDF file. I want to be able to convert existing documents into PDF format. The documents are 99% of the time going to be Microsoft Word documents so if there is a way to automate that, guidance there is appreciated.

I'm aware there are other methods of doing this such as downloading a "PDF Printer" but I would rather avoid that method if I could. I would also like to avoid downloading more software to install on user's PC's if possible as well.

Hopefully I am not being very demanding but I really do appreciate any help or guidance you can offer.

(As a Bonus I'd like to see if I can also get the option to Saves as PDF and Send as an attachment if possible.)

1
  • Office 2010 allows you to save as a PDF. What version of office are you using?
    – Bryan
    Jan 24, 2013 at 22:11

3 Answers 3

8

Here is the solution for Word 2013. It involves only adding a Visual Basic macro to Word and few records to the registry.

Create a global macro in Word 2013: open any document in Word, open the built-in Visual Basic editor (Alt + F11), select Normal in the left panel, click Insert in the main menu, then Module, and copy the code into the editor:

Sub ExportToPDFext()
    ChangeFileOpenDirectory ThisDocument.Path
    ActiveDocument.ExportAsFixedFormat _
        OutputFileName:=Left(ActiveDocument.FullName, InStrRev(ActiveDocument.FullName, ".")) + "pdf", _
        ExportFormat:=wdExportFormatPDF, _
        OpenAfterExport:=False, _
        OptimizeFor:=wdExportOptimizeForPrint, _
        Range:=wdExportAllDocument, _
        From:=1, _
        To:=1, _
        Item:=wdExportDocumentContent, _
        IncludeDocProps:=True, _
        KeepIRM:=True, _
        CreateBookmarks:=wdExportCreateNoBookmarks, _
        DocStructureTags:=True, _
        BitmapMissingFonts:=True, _
        UseISO19005_1:=False
    Application.Quit SaveChanges:=wdDoNotSaveChanges
End Sub

Save the module (Ctrl + S) and close Visual Basic editor and Word.

Then add the context menu options to registry. Create and execute a file with the extension .reg:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere]
@="Save PDF here"

[HKEY_CLASSES_ROOT\Word.Document.8\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\Office15\\WINWORD.EXE\" /mExportToPDFext /q \"%1\""

[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere]
@="Save PDF here"

[HKEY_CLASSES_ROOT\Word.Document.12\shell\SavePDFhere\command]
@="\"C:\\Program Files\\Microsoft Office\\Office15\\WINWORD.EXE\" /mExportToPDFext /q \"%1\"" 

The right-click "Save PDF here" will appear in Explorer for DOC and DOCX files.

It works silently and supports batch conversion of several selected documents.

3
  • Oleksiy, does this work with Word 2010 by a chance?
    – saulius2
    Dec 15, 2015 at 12:22
  • saulius2, unfortunately I don't have Word 2010 to check. Dec 15, 2015 at 15:44
  • I've checked this thing with Office 2010 a few days later. It works here too. Thanks.
    – saulius2
    Jan 24, 2016 at 13:55
4

Use the command line ability of PDFCreator to convert any printable file to PDF

  1. Download and install PDFCreator together with its COM module. The COM module is important or else the following VBscript can not comunicate with your PDF printer

  2. Copy & paste this code to a text file and save it as Convert2PDF.vbs

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set PDFCreator = Wscript.CreateObject("PDFCreator.clsPDFCreator", "PDFCreator_")
    
    With PDFCreator
     ReadyState = 0
     .cStart "/NoProcessingAtStartup"
     .cOption("UseAutosave") = 1
     .cOption("UseAutosaveDirectory") = 1
     .cOption("AutosaveFormat") = 0
     .cOption("AutosaveStartStandardProgram") = 0
     DefaultPrinter = .cDefaultprinter
     .cDefaultprinter = "PDFCreator"
     .cClearcache
     .cPrinterStop = false
     .cOption("AutosaveDirectory") = fso.GetParentFolderName(WScript.Arguments(0))
     .cOption("AutosaveFilename") = fso.GetBaseName(WScript.Arguments(0))
     .cPrintfile cStr(WScript.Arguments(0))
      c = 0
      Do While (ReadyState = 0) and (c < 120)
       c = c + 1
       Wscript.Sleep 250
      Loop
     .cDefaultprinter = DefaultPrinter
     .cClearcache
     WScript.Sleep 200
     .cClose
    End With
    
    Public Sub PDFCreator_eReady()
     ReadyState = 1
    End Sub
    
  3. Place a shortcut to your VBscript in your shell:sendto folder for faster access

    enter image description here

    (or)

    Execute your VBScript from the command line if you want full control over the output file name.
    Use this slightly changed code for this.

     C:\Convert2PDF.vbs "C:\inputfile.doc" "C:\outputfolder" "outputfilename"
    
1
  • Nice one. But I found PDCreator sometimes crashing inside the script. In such case it leaves default printer unrestored which is a pain for casual user. It probably would suffice to add few VBA statements for catching exceptions, but finally I chose using plain MS Office 2010:( since it works more realiably.
    – saulius2
    Jan 24, 2016 at 13:59
0

I apologize for forgetting about this question but at least I am finally answering the question, right?

I could not find a way to accomplish this the way I wanted so I did a slight workaround. I created and compiled 2 separate .ahk (AutoHotkey) scripts and added them to the right click context menus.

Here are the scripts:

Convert .DOC and .DOCX to PDF (Requires Office 2007 or 2010)

; AutoHotkey Script by Cyborg v1.5

; This script is designed to be compiled and ran in the user's Send To Right-Click Menu.
; The user needs to right click a word document go into the send to menu and choose this
; script. After launching the script the selected file will open in its version of Word
; and open the menus to save it as a PDF. In this version the user is unable to rename the
; the file.

; NOTE: In order for this to work correctly with Office 2007 you MUST have already installed
; the PDF/XPS converter from Microsoft.

SetTitleMatchMode 2

Loop %0%
{
Path := %A_Index%
Run,% Path
}

IfWinExist, Microsoft Word
    WinActivate

sleep 1000

Word2007:
IfExist, C:\Program Files (x86)\Microsoft Office\Office12\WINWORD.EXE ; Microsoft Word 2007
{
    Send ^s
    Send !f
    Send f
    Send p
    Sleep 500
    Send {Enter}
    Sleep 500
    WinClose, Microsoft Word
}
else
{
    Goto, Word2010
}
return

Word2010:
IfExist, C:\Program Files (x86)\Microsoft Office\Office14\WINWORD.EXE ; Microsoft Word 2010
{
    Send ^s
    Send !f
    Send d
    Send p
    Send a
    Sleep 500
    Send {Enter}
    Sleep 500
    WinClose, Microsoft Word
}
else
{
    Goto, Word2013
}
return

Convert .XLS and .XLSX to PDF (Requires Office 2007 or 2010)

; AutoHotkey Script by Cyborg v1.5

; This script is designed to be compiled and ran in the user's Send To Right-Click Menu.
; The user needs to right click a word document go into the send to menu and choose this
; script. After launching the script the selected file will open in its version of Excel
; and open the menus to save it as a PDF. In this version the user is unable to rename the
; the file.

; NOTE: In order for this to work correctly with Office 2007 you MUST have already installed
; the PDF/XPS converter from Microsoft.

SetTitleMatchMode 2

Loop %0%
{
Path := %A_Index%
Run,% Path
}

IfWinExist, Microsoft Excel
    WinActivate

sleep 1500

Excel2007:
IfExist, C:\Program Files (x86)\Microsoft Office\Office12\EXCEL.EXE ; Microsoft Excel 2007
{
    Send ^s
    Send !f
    Send f
    Send p
    Sleep 700
    Send {Enter}
    Sleep 700
    WinClose, Microsoft Excel
}
else
{
    Goto, Excel2010
}
return

Excel2010:
IfExist, C:\Program Files (x86)\Microsoft Office\Office14\EXCEL.EXE ; Microsoft Excel 2010
{
    Send ^s
    Send !f
    Send d
    Send p
    Send a
    Sleep 500
    Send {Enter}
    Sleep 500
    WinClose, Microsoft Excel
}
else
{
    Goto, Excel2013
}
return

Excel2013:
    MsgBox, Excel 2013 Not Configured for this Script.
return

Once I wrote these scripts and compiled them into .exes I placed them into the SendTo by following this guide by HowToGeek.

You may also be able to apply each script to each filetype but I didn't look into that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.