Jump to content
Sign in to follow this  
Mark Williams

Reset Printer

Recommended Posts

I'm using PDevMode to change printer settings.

Printer.GetPrinter(Device, Driver, Port, hDMode);
if (hDMode<>0) then
begin
  pDMode := GlobalLock(hDMode);
  if pDMode <> nil then
   	begin
      with pdMode^ do
      begin
        dmFields := DM_DEFAULTSOURCE;
        dmDefaultSource := ToBin;
        dmFields := dmFields or DM_PAPERSIZE;
        dmPaperSize := DMPAPER_A4; // Letter, 8-1/2 by 11 inches

        dmFields := dmFields or DM_PRINTQUALITY or DM_YRESOLUTION;
        if BestQuality then
          begin
            dmPrintQuality := LoWord(High_Quality);
            dmYResolution:=HiWord(High_Quality);
          end
        else
          begin
            dmPrintQuality := LoWord(Med_Quality);
            dmYResolution:=HiWord(Med_Quality);
          end;

        dmFields := dmFields or DM_DUPLEX;
        dmDuplex := DMDUP_VERTICAL;

        dmFields := dmFields or DM_COPIES;
      	dmCopies := Copies;
      end;
      GlobalunLock(hDMode);

This works fine if you only want to print one document or many documents with the exact same settings.

 

But I am printing various documents in a loop and different document get printed at different qualities, with different nos of copies and to different bins.

 

The problem is that once set the settings are saved and calling the above function does not change the settings for the new document.

 

One code example I found suggests the following:

Printer.GetPrinter(Device, Driver, Port, hDevmode);
{force reset of devmode}
Printer.SetPrinter(Device, Driver, Port, 0);
Printer.GetPrinter(Device, Driver, Port, hDevmode);

However, I then get a "Printer selected is not valid" error immediately I call Printer.BeginDoc.

 

I'm not sure what else to do. Have tried Printer.Refresh which is no help. 

 

I've come up with a clunky temporary solution which is to change the PrinterIndex immediately after Printer.EndDoc and then set it back to the desired printer. It works in clearing the settings, but I'm sure it is not the best way to do this!

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×