Chang Printer Driver Settings

I need to change some settings on a couple printer drivers.  Right now these settings are not persistent and we have to open the printer dialog (using Delphi's printer dialog control) and manually change the settings EVERY time we run the program.  It's a huge pain.  Is there any way to make these changes programmatically?  This is a very big deal for my company (we are talking about printing out thousands of items a day).  Thanks for any help.
pswensonAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
rwilson032697Connect With a Mentor Commented:
Here's a sample that changes the paper bin on the fly:

procedure TForm1.Button1Click(Sender: TObject);var
  ADevice, ADriver, APort: array [0..255] of char;  ADeviceMode: THandle;
  DevMode: PDevMode;begin    with Printer do begin
      GetPrinter(ADevice,ADriver,APort,ADeviceMode);
      SetPrinter(ADevice,ADriver,APort,0);
      GetPrinter(ADevice,ADriver,APort,ADeviceMode);
      DevMode := GlobalLock(ADeviceMode);
      if not Assigned(DevMode) then ShowMessage('Can''t set printer.')
      else begin        with DevMode^ do begin
          {Put any other settings you want here}
          dmDefaultSource := DMBIN_UPPER;
         {these codes are listed in "Windows.pas"}        end;
        GlobalUnlock(ADeviceMode);
        SetPrinter(ADevice,ADriver,APort,ADeviceMode);      end;    end;
    Printer.BeginDoc;
    Printer.Canvas.TextOut(50,50,'This page is printing from the UPPER PAPER TRAY.');
    with DevMode^ do begin      {Put any other settings you want here}
      dmDefaultSource := DMBIN_LOWER;
     {these codes are listed in "Windows.pas"}    end;
    Printer.NewPageDC(DevMode);
    Printer.Canvas.TextOut(50,50,'This page is printing from the LOWER PAPER TRAY.');
    Printer.EndDoc;end;


Here's the TDevMode structure with all the things you can change like this:

  _devicemodeA = packed record
    dmDeviceName: array[0..CCHDEVICENAME - 1] of AnsiChar;
    dmSpecVersion: Word;
    dmDriverVersion: Word;
    dmSize: Word;
    dmDriverExtra: Word;
    dmFields: DWORD;
    dmOrientation: SHORT;
    dmPaperSize: SHORT;
    dmPaperLength: SHORT;
    dmPaperWidth: SHORT;
    dmScale: SHORT;
    dmCopies: SHORT;
    dmDefaultSource: SHORT;
    dmPrintQuality: SHORT;
    dmColor: SHORT;
    dmDuplex: SHORT;
    dmYResolution: SHORT;
    dmTTOption: SHORT;
    dmCollate: SHORT;
    dmFormName: array[0..CCHFORMNAME - 1] of AnsiChar;
    dmLogPixels: Word;
    dmBitsPerPel: DWORD;
    dmPelsWidth: DWORD;
    dmPelsHeight: DWORD;
    dmDisplayFlags: DWORD;
    dmDisplayFrequency: DWORD;
    dmICMMethod: DWORD;
    dmICMIntent: DWORD;
    dmMediaType: DWORD;
    dmDitherType: DWORD;
    dmICCManufacturer: DWORD;
    dmICCModel: DWORD;
    dmPanningWidth: DWORD;
    dmPanningHeight: DWORD;
  end;

Hope this helps,

Cheers,

Raymond.

0
 
IndefreiCommented:
Try
Demos with sources at
www.beyersdorf.com
Shows values returned by GetDeviceCaps Windows API function
and how to handle them
maybe, it helps a little bit
cheers
Indi
0
 
IndefreiCommented:
Heiii, as far as i know Ex-Ex and their knowledge about printer
driver problems, i should give it as an answer
if it's not satisfying you can reject my answer of course
regards
Indi
0
[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

 
pswensonAuthor Commented:
Yeah, I'm aware of GetDeviceCaps.  But I was looking for specifics on how to parse the settings and change them.
0
 
IndefreiCommented:
Hei
pswenson,
if this is really betterfor you, let me know
Raymond, you're really somethng like a delphi monster
(as far as you remember the demolished discussion
about printer problems)
I see, you are still learning
and that's fine of course
H.a.n.d
Indi
0
 
rwilson032697Commented:
Hi Indy,

I'm not sure what you mean by "Delphi monster", but I'll take it as a compliment!

I don't remember a demolished discussion about printer problems though...

For the record, the code snippet came from UDDF, and the record structure from windows.pad...

h.a.n.d = have a nice day?

Cheers,

Raymond.
0
 
men xinCEOCommented:
you can put a printdialog component and
setup it's properties.of couse,you neednt excute it.

BTW:which setting are you want to change.
0
 
IndefreiCommented:
Raymond,

>> "Delphi monster", but I'll take it as a compliment!
That`s right.

>>discussion about printer problems
some printer often did not print images etc.

h.a.n.d = have a nice day !

Indi

0
 
IndefreiCommented:
0
 
pswensonAuthor Commented:
When I get a chance I'll evaluate the answer...may be a bit.  I'm working on about 8 projects right now!
0
 
IndefreiCommented:
It's really a problem, that printer problems ALLWAYS
get stuck here at EX-EX
I'd like to see a helpful hand, too
Indi
0
All Courses

From novice to tech pro — start learning today.