Fog Creek Software
Discussion Board




Does anyone know how to access printer defaults?


Hi All,

I've been having a really hard time with this and I thought I'd see if anyone here is familiar with this.

I'm working on an app that prints forms to a roll-fed printer. I need to be able to set the page length programmatically, but I cannot access it no matter what I try. The app is in .NET, but I've also been trying through VB6.

In .NET, enumerating through the printer sizes it shows the various widths supported by the printer with the height set to the current setting in the Printer Preferences. (This can be set in the print driver manually with no problems; I'm just trying to access this setting to automate it.) For each size, the .Kind returns "Custom", but when trying to set the .Height, it returns an error saying that the height can only be changed on sizes with a kind of Custom.

I've been through numerous Google searches but only found others with the same issue and no answers.

On MSDN they have two code samples that should work for this, but neither actually works. When printing from them they send the print but the page height is unaffected.

I assume that I'll have to programmatically access that page height setting from within the driver's preferences and basically change the default setting before printing. For this application that would be fine. I've determined that I apparently need to work with the DEVMODE in the driver. I have documentation of the structure, but no documentation of how to actually use this in .NET or VB6 to access the property and change it.

Does anyone here have any experience with this? I'd appreciate any tips, pointers, etc. Are there any components that might allow me to do this? A managed .NET wrapper would be perfect, but I can't find one. This is driving me crazy.

Thanks,

  --Josh

JWA
Saturday, May 17, 2003

Man this sounds familiar, basically what I struggled with last week.
We finally decided to set up a custom form since the printers that were printing the labels would only be using that form size and went with that.
In VB 6 you SHOULD be able to just use Printer.Height = <Form Height in Twips>, but of course that doesn't seem to work right depending on the print driver.
I really don't think Microsoft is to blame for this, but the print driver writers, since it seems that some print drivers work well with this and some don't...

ZiggaDigga
Sunday, May 18, 2003

Hi ZiggaDigga,

Would you mind sharing the method you used to add the custom form that actually worked? I've tried a number of ways, but I can't seem to get that to work either.

Regards,

  Josh

JWA
Sunday, May 18, 2003

What I did was go to to the printers folder on the workstation or server.
Click File >  Server Properties
It shoud open up to the Forms tab.
Just click the Create new form box, setup the size and margins, give it a name and save it.
After that you will need to set the printer up to use the new form.
Note, that some printer drivers do not play well custom form sizes, so this may not work for you. Luckily I was working on a little one off custom deal for a long time client, so they can deal with quirkiness...

ZiggaDigga
Sunday, May 18, 2003

Hi Zigga,

Oh, I see what you meant. This is going to be a shrink-wrapped program so I needed an automated way to do this programatically.

I've now resolved it. What I found works is to access the devmode for the printer through VB6 and make the changes, print from the main app, then set things back through the devmode. Apparently this is a known bug in .NET for now, but this will work for me.

Thanks for your help.

  --Josh

JWA
Monday, May 19, 2003

Try either of these 2.

http://www.mvps.org/vbnet/
Use the search facility for "printer"


http://www.mvps.org/vb/
Try "Samples" or API Index (Winspool.dll).

- Warning - this stuff uses API calls.

Justin
Monday, May 19, 2003

I really should pay more attention. DotNet. Ah well, that info might be of use to someone else.

Justin
Monday, May 19, 2003

*  Recent Topics

*  Fog Creek Home