Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Printing a Report Grayscaled

edited May 2004 in General
Hello NG.

First I must say, that my English isn't very well, because I'm from Germany.

Here is my problem.

I try to print a Report Grayscaled on a colorprinter, but it doesn't work.
How can I do this at run-time ??

Regards

Michael

Comments

  • edited May 2004
    Hi Michael,

    How are you telling the report to print in grayscale? ReportBuilder does
    not have any logic inside it that controls this feature of a printer. This
    may be an issue with either your printer driver or the default settings of
    your printer. As a test, try printing grayscale from another application,
    ie. MS Word and try printing your report on a different printer to see if
    the behavior is the same.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    Hi Nico.

    I try you to explain my Problem.
    Our Software prints only Text. If we print to a Colorprinter like "Canon BJC
    90" the printer driver says "Please insert the color Cartridge"
    Now i have thought its possible to say the report, to print grayscaled, so
    that this message doesn't pop up.
    The problem is, that we can't change the settings of the driver each time,
    because we are printing text and the next one want to print a Picture and
    must
    change the setting to "Color".

    For this reason I want to say at run-time that my report get printed
    grayscaled, but the next Printjob not.

    I think after reading this text you are very happy, because my English isn't
    very well :-)

    Regards

    Michael

  • edited May 2004
    Hi Michael,

    Don't worry, your English is much better than many Americans I know :).
    ReportBuilder accesses the DEVMODE structure of the Windows API to control
    the printer you are using. If you would like to control the color settings
    of the printer you are using, you will need to change the dmColor property
    value of this structure. See the Windows API help for more information on
    the DEVMODE structure. There is also an article and example below that may
    be helpful on how to extract the current DEVMODE while using RB.

    -------------------------------------------------
    Tech Tip: Configuring Printer Specific Options
    -------------------------------------------------

    The Report.PrinterSetup properties can be used to set the properties that
    are common to all printers. Internally RB applies these to the Windows
    DevMode structure.


    Report.PrinterSetup <----> Windows DevMode <-----> Printer Driver <--->
    Printer


    Printers often contains additional features, such as output bins, media
    types, etc. The Windows DevMode structure can contain a private area that is
    used the printer driver to store printer specific options. These can be
    configured by using the Printer Driver's built-in properties dialog. These
    options can theoritically be set programmatically, the trick is that you
    have to know where in the structure to store the option and what values are
    valid.

    The following example shows how to display the printer properties dialog and
    save the devmode for use within RB...

    http://www.digital-metaphors.com/tips/SavePrinterDevMode.zip




    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    Hello Nico.

    Thank you for the Tip.
    I try it, but it doesn't work.
    In my Application I insert following sourcecode

    procedure TForm1.Button2Click(Sender: TObject);
    var
    lPrinterDevice: TppPrinterDevice;
    begin
    lPrinterDevice := TppPrinterDevice.Create(nil);
    lPrinterDevice.Publisher := ppReport1.Publisher;
    lPrinterDevice.Printer.SetDevMode(DMCOLOR_MONOCHROME);
    ppReport1.PrintToDevices;
    lPrinterDevice.Free;
    end;

    But the Printer already asked for the Color Cartridge.
    What's wrong with my source ??

    Regards
    Michael

  • edited May 2004
    Hi Michael,

    Looking at your code below I notice a couple problems. The Device Mode is a
    Windows API structure that contains many separate enteries that control the
    printer. You are setting the entire structure to some integer constant
    DMCOLOR_MONOCHROME with your code below. First you will need to extract the
    DevMode structure by sending it the printer handle, then after requesting a
    global lock on the memory location, you can set the dbColor entery of the
    structure. Something like the following...

    var
    lPrinterDevice: TppPrinterDevice;
    lDevMode: THandle;
    lPDevMode: PDeviceMode;
    begin

    lPrinterDevice := TppPrinterDevice.Create(nil);
    lPrinterDevice.Publisher := ppReport1.Publisher;
    lPrinterDevice.Printer.GetDevMode(lDevMode);

    lPDevMode := GlobalLock(lDevMode);

    lPDevMode^.dmColor := DMCOLOR_MONOCHROME;

    GlobalUnlock(lDevMode);

    lPrinterDevice.Printer.SetDevMode(lDevMode);

    GlobalFree(lDevMode);

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    Hello Nico.

    Thank you for your help. But I'm going crazy :-)
    I've modified your code to this

    procedure TForm1.Button2Click(Sender: TObject);
    var
    lPrinterDevice: TppPrinterDevice;
    lDevMode: THandle;
    lPDevMode: PDeviceMode;
    begin
    lPrinterDevice := TppPrinterDevice.Create(nil);
    lPrinterDevice.Publisher := ppReport1.Publisher;
    lPrinterDevice.Printer.GetDevMode(lDevMode);

    lPDevMode := GlobalLock(lDevMode);

    lPDevMode^.dmColor := DMCOLOR_MONOCHROME;

    GlobalUnlock(lDevMode);

    lPrinterDevice.Printer.SetDevMode(lDevMode);

    GlobalFree(lDevMode);

    ppReport1.PrintToDevices;
    lPrinterDevice.Free;
    end;

    But it doesn't work. The printer shows a crazy behavior.
    If the color setting is "Color" it doesn't work.
    If I set the color settings of the driver manually to "Monochrome" AND
    change the DEVMODE then it works.
    If I set the color settings of the driver manually to "Monochrome" and not
    change the DEVMODE it doesn't work.

    Is it possible that I have placed the 2 lines

    ppReport1.PrintToDevices;
    lPrinterDevice.Free;

    at the wrong place ??

    Regards

    Michael


  • edited May 2004
    Hi Michael,

    Remember that the code I'm giving you is purely psuedo code. I'm not
    testing any of it. I'm unsure why this would not work on your printer. You
    may try calling PrintToDevices before freeing the lDevMode handle. This may
    also be a problem with your printer driver. Some printer drivers ignore the
    Windows settings and make up their own. I would recommend searching on
    Google Groups for anyone else who has run into this problem with your
    specific printer.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited May 2004
    Hello Nico.

    Thank you very much for your help.
    I think it's really a problem of the Canon Printerdriver.
    I've tested it with an Olivetti printer and it works.

    Regards

    Michael Meyer

This discussion has been closed.