views:

565

answers:

3

In our VB6 application, when the user's default printer is set to Microsoft Office Document Image Writer the following line of code causes the application to throw error number 380 (Invalid property value).

Printer.Orientation = vbPRORLandscape

If you are unfamiliar with what this line is doing, it is responsible for ensuring that the user's default printer is set up to print whatever is provided to it in landscape mode, and also provides landscape orientation dimensions (height/width) (on the Printer object) so following code can properly base item placement coordinates on the page.

I've Goggled around and it seems to be a generally accepted (and complained about) "missing feature" from the MODIW driver, for example see this thread. There were some workarounds like presenting the user with the Windows Printer Settings window (after presumably instructing them to select landscape in the options) or checking if the printer is the MODIW, and then preventing the user from generating the document that needs to be in landscape mode. There was another suggesting involving something called DEVMODE, but I didn't understand this suggestion, nor did I find a decent example, nor did I find anyone confirming that it worked.

I'm kinda at my wits end. Physical printers have no issue with this line; even the Microsoft XPS Document Writer and the various PDF printers I have tried have no issues with this line. I'm throwing this out here, hoping some awesome VB6 dev has found some previously undocumented way of making the orientation change with the Microsoft Office Document Image Writer driver.

A: 

Try this: PrintSchema.OrientationValue.Landscape

Take a look at this link CLICK ME (you will need to scroll down or better yet, do a search on the page for 'landscape') The issue discussed there is not the same as you describe but I think it will give you the answer you are looking for, if I understood you correctly.

Badfish
Thanks Badfish, but would you mind please elaborating on this suggestion? I didn't find a PrintSchema object to use in VB6 and Google didn't seem to be of any help on this suggestion as well.
ckittel
The link provided does have some suggestions. If you are using .NET and the OP isn't.
Corin
PrintSchema is WPF, so it's certainly not VB6. Nor does that page discuss ckittel's problem.
MarkJ
A: 

I haven't worked with the Document Image Writer, but this thread suggests that the orientation is actually controlled by a registry value. I get the feeling that the driver operates only in the mode indicated by the registry value and that it treats any value for the Print.Orientation property that does not match the registry value as invalid.

Corin
A: 

Here is a weird workaround you could try for this weird bug. Microsoft offer a free DLL that allows you to change the default settings for the printer, rather than just temporarily setting to landscape for the current document using the Printer object.

So you could try something like this (sample form code from the KnowledgeBase article). It changes the default orientation to landscape before doing any printing. Then it restores the original default orientation when the form is unloaded. I haven't tried this, don't know whether it will work.

Dim obj As PageSet.PrinterControl

Private Sub Command1_Click()
  On Error GoTo errorhandler:
  Set obj = New PrinterControl
  obj.ChngOrientationLandscape
  <Now do the printing>

  Exit Sub

errorhandler:
   MsgBox Err.Description
   obj.ReSetOrientation

End Sub


Private Sub Form_Unload(Cancel As Integer)

  obj.ReSetOrientation 'This resets the printer to portrait.'

End Sub
MarkJ