Home Devices

Printing a Report Builder report using Generic Text Print Driver

edited September 2005 in Devices
Hello,

Goal:
I am attempting to use a report created in Report Builder and print to a dot
matrix printer via the Generic Text Printer Driver.

The report's device type has been set to: ReportTextFile
fonts on the report have been set to Courier New

Problem:
I have received an improved report as far as the text, speed of the printing
and formatting. However, it is not perfect as some of the data is
overwritten.


I am using Report Builder demo\dm0107.pas as an example to follow. I was
not able to figure out where the ppReport1.FileDevice was set to a value
that was not nil so that the lDevice.CharacterGrid(120,66); can be set like
the dm0107.pas example.

Any tips or a more extensive example to use would be greatly appreciated.

Thanks,
Karen

Comments

  • edited September 2005
    Hi Karen,

    Are you first exporting the report to a text file (txt) then trying to print
    it to your matrix printer? You may want to try printing directly from
    ReportBuilder to your printer. Below is an article on what to look out for
    when printing to a matrix printer.

    -----------------------------------------------
    Article: Printing to Dot Matrix Printers
    -----------------------------------------------

    Dot matrix printers are natively line and character based. Most dot
    matrix printers can emulate graphical (i.e. pixel based) printing, but
    there is additional overhead which degrades printing speed.

    Some options for maximizing performance:

    1. Use native printer fonts.

    Each dot matrix printer normally has some built-in fonts. You can choose
    these fonts when using the ReportBuilder Report Designer. Choose File |
    PageSetup and select the dot matrix printer (or optionally use the
    object inspector to set Report.Printersetup.PrinterName). The fonts
    displayed in Report Designer's font drop down list located on the format
    toolbar will display the printer native fonts (indicated by a special
    printer icon next to the font name).

    2. Vertically position and size objects in 1/6 inch increments.

    A standard dot matrix printer can print 66 lines per 11 inch portrait
    page. This translates to a line height of 1/6 inch. Therefore the height
    of each band should be a multiple of 1/6 as should the size of the
    margins, the vertical position of each object etc.

    3. Keep the layout simple, avoid using graphics of any kind.

    Alternatives to using the dot matrix printer driver:

    1. Use the generic text printer driver.

    When using the generic text printer you will need to use the courier or
    courier new font and apply the layout techniques described above.

    2. Use ReportBuilder's ReportTextFile device output format.

    This ReportTextFile device can exports the report to a .txt file which
    you can then send to the printer. Demo dm0107.pas in the main reports
    demo app shows an example of printing a report to a .txt file and
    previewing the results.


    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2005
    Here is the code I am using to try to print to a dot matrix printer
    following the examples in the article mentioned below and also the
    demo/dm0107.pas

    When debugging, I noticed that
    1) Rpt1679r1.FileDevice IS nil.
    2) When assigning values to lDevice, I receive an AV error.



    procedure Tform1679.Rpt1679r1BeforePrint(Sender: TObject);
    var
    wb: boolean;
    lDevice : TppReportTextFileDevice;
    begin
    code, etc......
    more code, etc. and then the problem begins...... below when attempting
    to print to a dot matrix printer...... If I comment out the lDevice lines,
    then the report is misaligned in a few places and overwritten in a few
    places.




    else if (rpt1679r1.Tag = 2) then
    begin
    // ksh 9/8/2005: added for report tag #2
    Rpt1679r1.DeviceType := 'ReportTextFile';
    Rpt1679r1.TextFileName := ExtractFilePath (Application.ExeName) +
    'Rpt1679.txt';


    if (Rpt1679r1.FileDevice <> nil) and
    (Rpt1679r1.FileDevice is TppReportTextFileDevice) then
    begin

    lDevice := TppReportTextFileDevice(Rpt1679r1.FileDevice);
    lDevice.CharacterGrid(120,66);
    end;
    end;




    Looking forward to your assistance,

    Karen



  • edited September 2005
    Hi Karen,

    Setting the device type does not automatically create that file device. The
    file device will be created on demand when Print is called. Try setting the
    device properties after Report.Print has been called (perhaps in the
    BeforePrint event).

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2005
    Hi Nico,

    In my sample code below, you will see that I did assign the ldevices in the
    "BeforePrint" function.

    I have gotten beyond the ldevices being "nil" by creating a GetReport
    function like the one in dm0107.pas.

    Now my question is how do I get the newly created text file to "print"?

    I noticed that dm0107.pas has an afterprint procedure that states:
    memo1.Lines.loadfromfile (ppReport1.FileDevice.FileName);

    What call invokes the text report file to print?


    I am hoping to be able to print the newly created report text file without
    creating additional steps for the user beyond depressing the print button.

    Your suggestions are welcomed.

    Thanks,

    Karen



  • edited September 2005
    Hi Karen,

    Sorry, I didn't see that you were already using the BeforePrint event.
    Creating the device on the fly is probably the way to go with this.

    ReportBuilder is not equipt to directly print text files. The Lines
    property of the TppMemo is a TStringList object. The demo is utilizing the
    TStringList.LoadFromFile routine to load a text file into a TppMemo before
    printing a report. You may be able to experiment with this although I don't
    know if the output will be any better for a dot matrix printer. You may
    also try using the Delphi build-in TPrinter object to directly print the
    text file once it has been created.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2005
    Nico,

    Thanks for the new tip: to use the Delphi built-in TPrinter object.
    Is there a demo or example for this that I could see?

    Also, it was not clear to me in the demo dm0107.pas how the memo tstringlist
    object was printing the text file after it was loaded. Would you please
    explain.

    Thanks,

    Karen


  • edited September 2005
    Hi Karen,

    Unfortunately I do not have any experience using the TPrinter object
    although I believe it is well documented in the Delphi Help.

    Demo 107 simply exports a report to a Report Emulation Text file, then loads
    that text file into a Delphi TMemo located on the application form.

    If you wanted to use the TPrinter object to print a text file, you would
    need to write the memo text out to the Printer.Canvas after loading the text
    file into a memo object.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited September 2005
    Hi Karen,

    The following article may also be of some help.

    -----------------------------------------------
    Tech Tip: Send TextFile to Printer
    -----------------------------------------------

    I designed a application that exports the report to a .txt
    file using ReportTextFile device.

    How can I Send the text file to the printer?

    The following procedure will send the .txt file to
    the printer using Delphi's TPrinter object.



    uses
    Printers;


    procedure SendTextFileToPrinter(aFileName: String);
    var
    lsLines: TStringList;
    lOutputFile: TextFile;
    liIndex: Integer;
    begin

    lsLines := TStringList.Create;

    try
    lsLines.LoadFromFile(aFileName);

    AssignPrn(lOutputFile);
    Rewrite(lOutputFile);

    for liIndex := 0 to lsLines.Count-1 do
    Writeln(lOutputFile, lsLines[liIndex]);

    CloseFile(lOutputFile);

    finally
    lsLines.Free;
    end;


    end;

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
This discussion has been closed.