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

Printing PCL Direct to Printer

edited August 2013 in General
Hi,

We are using reportbuilder in our applications, but for one particular
place we are required to print a pre-compiled file (in PCL Format)
directly to the printer.

The file is a file on disk (ie page1.pcl) that we would like to send
through to the printer.

I can do this in a command line prompt using something such as:

type page1.pcl >lpt1:

or
type page1.pcl >\\machine\printer_share_name

I was wondering if there is a way to print this file using reportbuilder?

Thanks & Regards

Adam.

Comments

  • edited August 2013

    You can use the Report.OnPrinterDeviceStateChange event and the
    Report.Printer.SendEscape method to send PCL commands directly to the
    printer. Check out the RBuilder help topic for the TppProducer
    OnPrinterDeviceStateChange event, it contains some sample code (Producer is
    an ancestor to Report). The SendEscape method accepts a command string, you
    can use TStringList to load the .pcl file. Currently the command string is
    limited to 256 characters in length. For RB 15.01 I will enhance it to
    accept any length.


    -
    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited August 2013
    Hi Nard,


    Thanks for your reply...

    I will wait until RB 15.01 before implementing as the file is rather
    large, and I would like to be able to load it in one hit.

    In the mean time, I have stumbled across the following that will let me
    work. Unfortunately it doesn't use reportbuilder, but will let me
    through for the time being.

    Thanks again for your help, and I'll await 15.01.

    Best Regards

    Adam.

    uses
    Printers, Winspool;

    function SpoolFile(const FileName, PrinterName: string): Integer;
    var
    Buffer: record
    JobInfo: record // ADDJOB_INFO_1
    Path: PChar;
    JobID: DWORD;
    end;
    PathBuffer: array[0..255] of Char;
    end;
    SizeNeeded: DWORD;
    Handle: THandle;
    PrtName: string;
    ok: Boolean;
    begin
    // Flush job to printer
    PrtName := PrinterName;
    if PrtName = '' then
    PrtName := Printer.Printers[Printer.PrinterIndex]; // Default
    printer name
    ok := False;
    if OpenPrinter(PChar(PrtName), Handle, nil) then
    if AddJob(Handle, 1, @Buffer, SizeOf(Buffer), SizeNeeded) then
    if CopyFile(PChar(FileName), Buffer.JobInfo.Path, True) then
    if ScheduleJob(Handle, Buffer.JobInfo.JobID) then
    ok := True;
    if not ok then Result := GetLastError
    else
    Result := 0;
    end;


    procedure TForm1.Button1Click(Sender: TObject);
    begin
    if SpoolFile('c:\test.prn', Printer.Printers[0]) = 0 then
    ShowMessage('No error...');
    end;
This discussion has been closed.