Black Ice Software
November Developer News
Volume 12, Issue 11 - November, 2007
The BLACK ICE NEWSLETTER is published by Black Ice Software, LLC. The contents of this newsletter in its entirety are Copyright © 2007 by Black Ice Software, LLC. 292 Route 101, Salzburg Square, Amherst, NH 03031, USA. Black Ice Software, LLC. does hereby give permission to reproduce material contained in this newsletter, provided credit is given to the source, and a copy of the publication that the material appears in is sent to Black Ice Software at the above address. Phone: (603) 673-1019 Fax: (603) 672-4112 sales@blackice.com www.blackice.com

How to Set Common Printer Driver Settings Depending on a Physical Printer

 

There can be cases when you want the exact same output with the Black Ice printer as from a physical printer in your office without using printer redirection. For example:

     1.  You print a word document to a physical printer in your office and to the Black Ice Color printer
 

    2.  Later, you print the jpg file generated by the Black Ice Color printer driver to the same physical printer as before

You want to get the same content, pixel for pixel, on both printed papers.

 To create the exact same output you need to set the common settings of the Black Ice printer depending on the physical printer being used. The following steps below show you how to set the printer driver programmatically in C++:

 For the entire source code, see the TransferSettings function of the “Setup Redirect Printing” C++ Sample in the printer driver resource toolkit. If you call the TransferSettings function before printing to the Black Ice printer, the Black Ice printer sets its settings depending on the physical printer. If you then print the JPG to the same physical printer, the printing output will be the same as the document you printed directly to the physical printer.

 

1. Open the physical printer and get printer info structure:

 

// …

// Open the printer

if (!OpenPrinter(szSelectedPrinterName, &hPrinter, NULL))

{

wsprintf(szError, TEXT("Error opening '%s', Error %d"), szSelectedPrinterName, dwError);

    AfxMessageBox(szError);

    return;

}

// …

// Get printer info

bFlag = GetPrinter(hPrinter, 2, (LPBYTE)pi2, dwNeeded, &dwNeeded);

// …

 

2. Get physical printer settings

 

// …

// Get physical printer common settings

nPaperSize        = pi2->pDevMode->dmPaperSize;

nOrientation      = pi2->pDevMode->dmOrientation;

nPaperWidth       = pi2->pDevMode->dmPaperWidth;

nPaperHeight      = pi2->pDevMode->dmPaperLength;

dwXDPI            = pi2->pDevMode->dmPrintQuality;

// …

 

3. Set Black Ice printer

 

// …

if (nPaperSize)

{

    SetPaperSize(nPaperSize, pBlackIceDevMode);

    SetOrientation(nOrientation, pBlackIceDevMode);

    DisableRotatePaper(pBlackIceDevMode);

}

else

{

    SetPaperSize(DMPAPER_VARIABLE, pBlackIceDevMode);

    SetPaperWidth(nPaperWidth, pBlackIceDevMode);

    SetPaperLength(nPaperHeight, pBlackIceDevMode);

}

 

SetXDPI(dwXDPI, pBlackIceDevMode);

SetYDPI(dwYDPI, pBlackIceDevMode);

     

SetPagePhysicalOffsetX(dwXOffset, pBlackIceDevMode);

SetPagePhysicalOffsetY(dwYOffset, pBlackIceDevMode);

// …

 

4. Save the Black Ice devmode structure:

 

// …

if (!SaveBlackIceDEVMODE(m_szBlackIcePrinter.GetBuffer(MAX_PATH), pBlackIceDevMode))

{

      DWORD e = BlackIce_GetLastError();

      AfxMessageBox(TEXT("Error saving the printer settings."));

}

else

{

      AfxMessageBox(TEXT("The printer settings were successfully

 saved"));

}

// …