The Following C# code demonstrates how to change the printer driver setting before printing for File Format, Output directory, and to load a predefined profile.
To be able to change the Printer Driver settings, the BlackIceDEVMODE ActiveX Control reference should be added to the C# project in Visual Studio.
For detailed description about how to add Active X control to your C# project, please refer to the Registering the ActiveX Controls section.
For 32 bit
// This function changes a few printer settings in the specified printer driver
public void ChangeSettings(string szPrinterName)
{
// Creating BlackIceDEVMODE object
BLACKICEDEVMODELib.BlackIceDEVMODE BiDevmode;
BiDevmode = new BLACKICEDEVMODELib.BlackIceDEVMODE();
// Create a new BlackIceDEVMODE structure and load current printing settings
int pDevMode = BiDevmode.LoadBlackIceDEVMODE(szPrinterName);
// Set the output directory
BiDevmode.SetOutputDirectory(@"<<USERPROFILE>>\Documents", pDevMode);
// Set output file format to "PDF"
BiDevmode.SetFileFormat(36, pDevMode);
// Apply the new settings and release the BlackICeDEVMODE structure
BiDevmode.SaveBlackIceDEVMODE(szPrinterName, pDevMode);
BiDevmode.ReleaseBlackIceDEVMODE(pDevMode);
}
// This function loads a profile into the specified printer
public void LoadProfile(string szPrinterName, string szProfileName)
{
// Creating BlackIceDEVMODE object
BLACKICEDEVMODELib.BlackIceDEVMODE BiDevmode;
BiDevmode = new BLACKICEDEVMODELib.BlackIceDEVMODE();
// Create a new BlackIceDEVMODE structure and load current printing settings
int pDevMode = BiDevmode.LoadBlackIceDEVMODE(szPrinterName);
// Load a printer driver profile.
// Settings that are stored in the registry get applied immediately,
// settings that are stored in the BlackIceDEVMODE structure get loaded to pDevMode
// and get applied when we call SaveBlackIceDEVMODE
BiDevmode.ApplyProfile(szPrinterName, szProfileName, pDevMode);
// Apply the new settings and release the BlackICeDEVMODE structure
BiDevmode.SaveBlackIceDEVMODE(szPrinterName, pDevMode);
BiDevmode.ReleaseBlackIceDEVMODE(pDevMode);
}
// Using the functions:
// Change some of the printer settings.
ChangeSettings("Black Ice ColorPlus");
// Or load one of the profiles.
// To load a printer profile, the sample must be compiled to the same
// platform as the printer driver, so for 64 bit systems, set the platform to x64
LoadProfile("Black Ice ColorPlus", "Display BMP");
For 64 bit
// This function changes a few printer settings in the specified printer driver
public void ChangeSettings(string szPrinterName)
{
// Creating BlackIceDEVMODE object
BLACKICEDEVMODELib.BlackIceDEVMODE BiDevmode;
BiDevmode = new BLACKICEDEVMODELib.BlackIceDEVMODE();
// Create a new BlackIceDEVMODE structure and load current printing settings
long pDevMode = BiDevmode.LoadBlackIceDEVMODE(szPrinterName);
// Set the output directory
BiDevmode.SetOutputDirectory(@"<<USERPROFILE>>\Documents", pDevMode);
// Set output file format to "PDF"
BiDevmode.SetFileFormat(36, pDevMode);
// Apply the new settings and release the BlackICeDEVMODE structure
BiDevmode.SaveBlackIceDEVMODE(szPrinterName, pDevMode);
BiDevmode.ReleaseBlackIceDEVMODE(pDevMode);
}
// This function loads a profile into the specified printer
public void LoadProfile(string szPrinterName, string szProfileName)
{
// Creating BlackIceDEVMODE object
BLACKICEDEVMODELib.BlackIceDEVMODE BiDevmode;
BiDevmode = new BLACKICEDEVMODELib.BlackIceDEVMODE();
// Create a new BlackIceDEVMODE structure and load current printing settings
long pDevMode = BiDevmode.LoadBlackIceDEVMODE(szPrinterName);
// Load a printer driver profile.
// Settings that are stored in the registry get applied immediately,
// settings that are stored in the BlackIceDEVMODE structure get loaded to pDevMode
// and get applied when we call SaveBlackIceDEVMODE
BiDevmode.ApplyProfile(szPrinterName, szProfileName, pDevMode);
// Apply the new settings and release the BlackICeDEVMODE structure
BiDevmode.SaveBlackIceDEVMODE(szPrinterName, pDevMode);
BiDevmode.ReleaseBlackIceDEVMODE(pDevMode);
}
// Using the functions:
// Change some of the printer settings.
ChangeSettings("Black Ice ColorPlus");
// Or load one of the profiles.
// To load a printer profile, the sample must be compiled to the same
// platform as the printer driver, so for 64 bit systems, set the platform to x64
LoadProfile("Black Ice ColorPlus", "Display BMP");