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

Printing with ReportTextFile Device

edited August 2007 in Devices
hi,

i am using Reportbuilder 10.6 and i want to print with the ReportTextFile
Device, i have already read the 107 demo example and i am not sure i have
fully undersatnd the way it was made because the report was developed with a
non standard paper size as far as i know (Width=5100,Height=6600) and the
charactergrid used to emulate the text version of the report was 120
characters per line and 66 lines per page wich i didnt fully understand how
it was determined so i can make my own report with A5 paper size and obtanin
a correct text report translation.

thanks.

Comments

  • edited August 2007

    In demo 107....

    Report.Units := utPrinterPixels
    Report.PrinterSetup.PaperName := 'Letter'

    Thus, if your printer has a resolution of 600 pixels per inch, then the
    paper dimensions are calculated as follows:

    PaperWidth = 600 * 8.5 = 5100
    PaperHeight = 600 * 11 = 6600

    When I set Report.PrinterSetup.PaperName to 'A5', the paper dimensions are
    calculated

    PaperWidth := 3496
    PaperHeight := 4961

    If you do not call the CharacterGrid method, then RB will internally
    calculated the grid size. It does this by measuring the font text height and
    width and the page size. (In the demo, that should really be 80 chars per
    line and 66 lines per page).




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



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited August 2007
    hi Nard,

    thanks for your fast reply, now i understand how the paper size dimensions
    are calculated for each printer resolution, i removed the CharacterGrid
    method from the AfterPrint
    event to let the ReportTextFile device calculate the grid size like you said
    and i can see the resulting text file is generated correctly but when i send
    the resulting lines to the printer with this code :

    function TFrmMain.DirectToPrinter(S: string; NextLine: Boolean): Boolean;
    var
    Buff: TPrnBuffRec;
    TestInt: Integer;
    begin
    TestInt := PassThrough;
    if Escape(Printer.Handle, QUERYESCSUPPORT, SizeOf(TESTINT), @testint, nil)
    begin
    if NextLine then S := S + #10;
    StrPCopy(Buff.Buff_1, S);
    Buff.bufflength := StrLen(Buff.Buff_1);
    Escape(Printer.Canvas.Handle, Passthrough, 0, @buff, nil);
    Result := True;
    end
    else
    Result := False;
    end;


    procedure TFrmMain.ppReport1AfterPrint(Sender: TObject);
    var fTextFile : TextFile;
    sText : string;
    begin
    if (ppReport1.FileDevice <> nil) then
    begin
    // Label10.Caption := ppReport1.FileDevice.FileName;

    // Memo1.Lines.LoadFromFile(ppReport1.FileDevice.FileName);

    // this code works if the printer supports escape commands
    // you can get special esc codes from printer's manual

    // example:
    try
    printer.BeginDoc;
    AssignFile(fTextFile,'C:\test.txt');
    Reset(fTextFile);
    while not eof(fTextFile) do
    begin
    Readln(fTextFile,sText);
    directtoprinter(sText,True);
    end;
    finally
    printer.EndDoc;
    end;

    end;

    end;

    it feeds the 'A5' paper for one and half a page which i didnt understand
    why, am i doing this wrong i mean sending the text file generated to the
    printer by direct printing please feel free to point me in the right
    direction so i can make it correctly a simple example like the demo 107
    printing directly to the dot matrix printer would be great, in the mean time
    i will continue my struggling to get it work correctly hope you can help me.

    thanks

    "MAAZAOUI Imed" a écrit dans le message de
  • edited August 2007

    - Your DirectToPrinter code uses Delphi's global Printer object which is an
    instance of the TPrinter class. Try configuring the Printer object with the
    desired paper size, prior to calling Printer.BeginDoc.

    - The other thing you could try is to use the RB Printer instead. Perhaps
    something like this...

    myReportLines := TStringList.Create;
    myReportLines.LoadFromFile('c:\myReportFile.txt');

    myReport.Printer.BegingDoc;

    for liIndex := 0 to myReportLines.Count-1 do
    begin
    lsReportLine := myReportLines[liIndex];

    // add code to load the buffer with lsReportLine

    Escape(myReport.Printer.Canvas.handle, PassThrough, @Buffer, nil);

    end;

    myReport.Printer.EndDoc;




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



    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.