• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2258
  • Last Modified:

Printing to Microsoft Office Document Image Writer launches the viewer

I want to create an MDI file by printing to Microsoft Office Document Image Writer. That part is easy; the VB6 code below does it quite nicely.

But there is one problem with it. The moment it creates the file ... it launches the MDI viewer. I don't want it to launch the viewer. I will be processing the file myself, through code.

How do I stop it from launching the viewer!?
For Each oPrinter In Printers
        MsgBox oPrinter.DeviceName
        If InStr(1, oPrinter.DeviceName, "Microsoft Office Document Image Writer", vbTextCompare) > 0 Then
            Exit For
        End If
Next
If Not oPrinter Is Nothing Then
        Set oWord = New Word.Application
        oWord.ActivePrinter = oPrinter.DeviceName
        Set oWordDoc = oWord.Documents.Open(strNew)
        oWordDoc.SaveAs Environ("TEMP") & "\eek.mdi"
        oWordDoc.PrintOut Range:=wdPrintAllPages, Collate:=True, PrintToFile:=True, OutputFileName:=Environ("TEMP") & "\eek.mdi"
        oWordDoc.Close False
        Set oWordDoc = Nothing
        oWord.Quit False
        Set oWord = Nothing
End If

Open in new window

0
WernerVonBraun
Asked:
WernerVonBraun
  • 5
  • 3
1 Solution
 
Antagony1960Commented:
This appears to be a function of the MODIW's printer driver and it doesn't seem to have an option to turn it off. However, if you change the default output to Tiff it will not launch the viewer. To do that, go into Control Panel¦Printers and right-click the MODIW printer and select 'Properties', then click on 'Printing Preferences' and go to the 'Advanced' tab. In there change the output type to Tiff - Monochrome and set the quality (in the drop-down) to 'Super Fine 300'. You can still leave the output file as .mdi and it will still open in the MDI viewer.

If Tiff output is not acceptable, the only other thing I can think of is to scan the windows process list and kill the viewer after it's been launched. I have code to do that if you need it.
0
 
WernerVonBraunAuthor Commented:
I actually found a way around the problem. When you go to Word, and you manually print, and you choose the MODI printer, there is actually a tick box at the bottom after you click ok that says, imagine that, "view document image". And when you uncheck that, guess what ... the problem goes away in the code too.

HOWEVER, I've since come up against an even worse problem. The output from the .Printout call is inconsistent. I tried this with a four-page document. And the mdi file contains ... well. Sometimes one page. Sometimes two. Sometimes all four.

Oh the joy.

I suppose you don't know how to send a word document to a specified printer through a shell (command line) commannd, do you? I'm now thinking I'll just invoke it through a synchronous shell; that is, IF I can work out how to do it.
0
 
Antagony1960Commented:
Yeah, the basic shell command is useless for passing parameters. I use the ShellExecute API. See the vbAccelerator page below for details on using that. It shows how to print a document.

http://www.vbaccelerator.com/codelib/shell/shellex.htm
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
WernerVonBraunAuthor Commented:
<shudder>

Dude, this is nuts. I made a small change and guess what, now it works! Check it out. So thankfully I don't need to try and run it as a command line argument.

Now then, all I need next is to convert a PDF to images, and then I'm laughing all the way to the bank.

P

See code:
    For Each oPrinter In Printers
        If InStr(1, oPrinter.DeviceName, "Microsoft Office Document Image Writer", vbTextCompare) > 0 Then
            Exit For
        End If
    Next
    If Not oPrinter Is Nothing Then
        sDriver = oPrinter.DeviceName
    End If
    Set oPrinter = Nothing
    
    Set oWord = New Word.Application
    Set oWordDoc = oWord.Documents.Open(strNew)
    oWord.PrintOut False, , , Environ("TEMP") & "\eek.mdi"
    oWordDoc.Close
    Set oWordDoc = Nothing
    oWord.Quit
    Set oWord = Nothing
    strNew = Environ("TEMP") & "\eek.mdi"

Open in new window

0
 
WernerVonBraunAuthor Commented:
pardon.

again:
    For Each oPrinter In Printers
        If InStr(1, oPrinter.DeviceName, "Microsoft Office Document Image Writer", vbTextCompare) > 0 Then
            Exit For
        End If
    Next
    If Not oPrinter Is Nothing Then
        sDriver = oPrinter.DeviceName
    End If
    Set oPrinter = Nothing
    
    Set oWord = New Word.Application
    oWord.ActivePrinter = sDriver
    Set oWordDoc = oWord.Documents.Open(strNew)
    oWord.PrintOut False, , , Environ("TEMP") & "\eek.mdi"
    oWordDoc.Close
    Set oWordDoc = Nothing
    oWord.Quit
    Set oWord = Nothing

Open in new window

0
 
WernerVonBraunAuthor Commented:
I think the main difference is that the printout is not background, forcing it to show a little dialog saying printing page 1 of ... going through the pages 1, 2, 3, 4. And so it always includes all the pages. Problem solved.

this was bizarre. A whole morning of my life that I'll never get back.
0
 
Antagony1960Commented:
No but you've added to the wealth of your experience. ;)
0
 
WernerVonBraunAuthor Commented:
Hell yeah. The School of Hard Knocks. LOL
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now