Intercept PDF export in Word

Add-in Express™ Support Service
That's what is more important than anything else

Intercept PDF export in Word

Posts: 19
Joined: 2017-12-30
Is there a way to intercept the PDF export event in Word (before or after)?

We would like to

1. Get info that user has attempted to export the doc as PDF.
2. Get info regarding the path of the PDF file and possibly do some modifications (before the PDF is opened in Acrobat or others).
Posted 10 Jul, 2018 05:55:02 Top
Andrei Smolin

Add-in Express team

Posts: 16568
Joined: 2006-05-11
I assume you won't be able to intercept saving to PDF if you use the Save As dialog. This means you will need to hide that Backstage tab so that the user only uses the paths that you intercept.

In the list of commands that Word provides there's a Ribbon button having IdMso="FileSaveAsPdfOrXps". You can intercept that command in these scenarios: 1) you click a custom ADXRibbonButton having the IdMso property set to "FileSaveAsPdfOrXps", 2) in the code of your add-in, you get WordApp.CommandBars and call CommandBars.ExecuteMso("FileSaveAsPdfOrXps").

To intercept the file name however, you would need to create a Word.Dialog of the WdWordDialog.wdDialogExportAsFixedFormat type, call Dialog.Display(), get the file name chosen by the user and call Document.ExportAsFixedFormat(). You may want to check a sample project accompanying the blog at; it shows how to invoke a Word.Dialog, get and set its parameters. Unfortunately, in the code of that add-in I see that specifically that dialog doesn't define parameters. This means, you won't be able to extract the settings the user chosen while using this dialog. This means, you need to provide a UI allowing the user to specify parameters for the Document.ExportAsFixedFormat() method.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 10 Jul, 2018 07:26:24 Top