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

Sending esc codes to the printer (driver)

edited June 2003 in General
Hello,
I use D6, RB6.03 Pro.
My reports are in Hebrew (right-to-left writing order).
In order to produce a PDF report, the best solution I found is using a
printer driver that produces a PDF file from
the print output. Using filters like Pragnaan or waller does not work, they
don't support RTL output for PDF.
The driver that does RTL PDF OK needs, in order to specify the output file
name, to send escape sequence to the printer
and I quote the tech manual: "1. The escape codes have to be sent after
PrinterDC is ready and before calling StartDoc(). (CREATEDC_POST) "

How can I do that using Report Builder. I noticed that the BeforePrint event
is triggered too early and the printer dc is built
after.
How can I do it?

TIA
Israel

Comments

  • edited June 2003
    Hook into the printer device's OnStartJob. This will fire in the ancestor
    TppDevice which is when the StartJob method is called, but before the
    descendent TppPrinterDevice has called BeginDoc which resets the DC and
    calls Delphi's StartDoc function declared in Windows.pas.

    In the Report.BeforePrint event, check
    if (ppReport1.PrinterDevice <> nil) then
    ppReport1.PrinterDevice.OnStartJob := StartJobEvent;

    As a last resort, if you have to, you can create your own TmyPrinterDevice
    and register this as a new device, as it is a copy of TppPrinterDevice in
    ppPrnDev.pas which has been renamed. Then you can add an event notification
    where you want to in your device to be able to add escape codes when you
    want to. There is a Report.PrintToDevices which can be used when you want to
    control the print process manually.

    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    Thanks Jim but...

    notification
    to

    I tried it upto the point I realized that the BeginDoc is a procedure of
    TppCustomPrinter that I cant override.
    I need to trigger my custom event in the position marked with ***** in the
    following code.


    procedure TppCustomPrinter.BeginDoc;
    var
    lDocInfo: TDocInfo;
    begin

    if FPrinting then Exit;

    FPrinting := True;
    FAborted := False;
    FPageNumber := 0;
    FStartPage := False;

    {free the current device context and call resetDC to create a new one}
    FreeDC;
    ResetDC;

    **************************************************************
    I need to triger the event/send escape codes - here
    **************************************************************

    FillChar(lDocInfo, SizeOf(lDocInfo), 0);
    lDocInfo.cbSize := SizeOf(lDocInfo);
    lDocInfo.lpszDocName := PChar(FDocumentName);

    if (FFileName <> '') then
    lDocInfo.lpszOutput := PChar(FFileName);

    {SetAbortProc(FDC, AbortProc);}
    StartDoc(FDC, lDocInfo);

    end; {procedure, BeginDoc}


    In addition there is a problem overriding the procedure
    TppPrinterDevice.StartJob, in order to control the calling to BeginDoc
    because the last line is FCanvas := Printer.Canvas and the Canvas property
    is readonly so you cant do a Canvas := Printer.Canvas.

    How do I go from here?

    Israel
  • edited June 2003
    If you have to modify the TppPrinter class, then you'll have to change your
    library path to RBuilder\Source and change the source. Are you using RAP? If
    so, then you won't want to change the interface section of any class, but
    you'll have to in this case, because TppPrinter is not a TppCommunicator so
    it can't broadcast a message to any other object. The easiest thing to do is
    to add a TNotifyEvent on this class and hook into it by the
    TppReport.Printer property at runtime, rather than creating an embedded
    TppCommunicator. If you want to go with the more powerful communicator
    approach, then take a look at the TppViewer class in ppViewr.pas, as it
    creates an embedded TppCommunicator in order to communicate.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    back again Jim,

  • edited June 2003
    Hi,

    i found this a very good feature, to insert ESC Codes before and after
    Print.
    With this i could handle cash-drawer to open and also to cut paper.
    It might be a littlte difficult to overwrtite the printer. If possible, put
    such an option to your ToDo-List for the next generation. So ESC-Codes could
    be inserted easyly before and after a report (with RAP and perhaps as a
    property of the Report.).

    chris



  • edited June 2003
    TppPrinter objects are create-embedded on different objects. I'd have to
    code an example to research this feature further. Let me know in the
    meantime if you get it working.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited June 2003
    Hi Jim,
    been away but this issue is still very important.

This discussion has been closed.