Tag Archives: Windows Development

Suppressing the MODI Popup using C#

For those of you who have never heard of the MODI acronym it stands for
the Microsoft Office Document Image writer, which is a virtual printer
driver for converting printed content into Microsoft Document Images or
TIFF files. The idea for this virtual printer, shipped with Office, is
to provide a means for converting output from applications with
printing ability into a format that can be read by Office applications.

I am working on a project that converts known file formats into TIFF
images, so MODI is ideal for this task. The project involves converting
multiple files at once, using multi-threading. Converting Office type
documents with MODI was easy, Word, Excel, PowerPoint
etc, provide printing ability using a COM API. The method call in these
application interfaces requires a printer name and filename to save to,
if using virtual printers like MODI. Life is good. The problem comes
about when using non-Office applications, such as Internet Explorer,
to print using MODI. The print method in IE’s API does not provide a
way to specify the output file, as with the Office applications, so
during the print request MODI pops up a helpful dialog box – great in a
single thread printing environment, bad in a multi-threaded application
with lots of print jobs.

I scoured the web looking for a quick fix to the MODI pop up problem but
found very little help. Microsoft provides an API for MODI but it is
designed for sending documents to the driver, not manipulating the
driver options. The only helpful hint I came across was to post
or send messages to the dialog window that MODI pops up, thus simulating a user
pressing the “save” button. Using this idea I got to work on writing a
class that would manipulate the MODI pop up window from C#.

I wrote a simple class that will manipulate any instance of  MODI
pop up window that is found on the system. The class uses Win32 API
calls to find the “Save As” window with the same characteristics used
by MODI. Once found I can send Windows messages to the controls on the
form to change the file name location and click the save button.
MODI typically displays the pop up window a short time after a print
request has been made. This time is dependent on the sized of the data
being sent to the MODI printer. Most applications use the spooler to
print to MODI and the print call is asynchronous, meaning the call will
return immediately after spooling before printing starts. It is not
enough to detect the pop up window directly after a print method
because the MODI may still be busy and the pop up will be missed. So I
wrote functionality into my class to wait for an expected MODI pop up
window for a finite period of time.

Below is an example of how to call my class using C#. My class can also
be called from VB.Net, or any other .Net language, only the syntax will
change accordingly.

// Called after a print method invocation.
// Wait 5 seconds for the window to appear.
// If the null is returned no window could be detected.
MODIWindow window = MODIWindow.WaitForWindow(5);
if (null != window)
// Change the filename.
window.Filename = “c:newfile.mdi”;
// Make the window go away by simulating clicking save.

The code for the MODI Window class can be found Here.