Receipt Printing
Hi All
I am using Report Builder 6.03 and Delphi Pro 6 to print out to an Epson
TM 88 - III Thermal Receipt Printer.
As this printer uses thermal paper on a roll similar to fax machines I
don't want to use an arbitrary Page size and I was wondering if there
was a way to calculate the Page size at runtime? The current solution
that I have is to add up the size of the Title, Header, Footer Bands and
then add the Height of the Detail Band x Number of Lines. However I am
planing to make the Detail Band Height dynamic and I would like it if
the receipt had as little white space as possible. So is there a
CalculateReportHeight (or function to that effect) than I can use?
Thanks in Advance
Peter Magor
I am using Report Builder 6.03 and Delphi Pro 6 to print out to an Epson
TM 88 - III Thermal Receipt Printer.
As this printer uses thermal paper on a roll similar to fax machines I
don't want to use an arbitrary Page size and I was wondering if there
was a way to calculate the Page size at runtime? The current solution
that I have is to add up the size of the Title, Header, Footer Bands and
then add the Height of the Detail Band x Number of Lines. However I am
planing to make the Detail Band Height dynamic and I would like it if
the receipt had as little white space as possible. So is there a
CalculateReportHeight (or function to that effect) than I can use?
Thanks in Advance
Peter Magor
This discussion has been closed.
Comments
even when the detail band is dynamic height:
http://www.digital-metaphors.com/tips/CalculateReceiptPageHeight.zip
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
open it in RB 6.03, then use this class to do the work for you:
unit ReportHeightCalculator;
interface
uses
ppReport;
type
TppReportHeightCalculator = class
private
FDetailStopPosition: Integer;
FUsedHeight: Integer;
FReport: TppReport;
procedure SetVisibleBands(aReport: TppReport; aVisible: Boolean);
function SumTheHeights: Double;
procedure DetailBandAfterPrintHandler(Sender: TObject);
procedure ReportEndPageHandler(Sender: TObject);
public
constructor Create;
function CalculatePageHeight(aReport: TppReport): Double;
end;
implementation
uses
ppDevice,
ppTypes,
ppUtils;
constructor TppReportHeightCalculator.Create;
begin
FDetailStopPosition := 0;
FUsedHeight := 0;
FReport := nil;
end;
function TppReportHeightCalculator.CalculatePageHeight(aReport: TppReport):
Double;
var
lDevice: TppDevice;
begin
lDevice := TppDevice.Create(nil);
try
FReport := aReport;
FUsedHeight := 0;
{connect calc events}
SetVisibleBands(FReport, False);
FReport.OnEndPage := ReportEndPageHandler;
FReport.DetailBand.AfterPrint := DetailBandAfterPrintHandler;
lDevice.PageSetting := psAll;
lDevice.Publisher := FReport.Publisher;
FReport.PrintToDevices;
FReport.Reset;
finally
SetVisibleBands(FReport, True);
FReport.OnEndPage := nil;
FReport.DetailBand.AfterPrint := nil;
lDevice.Free;
end;
Result := SumTheHeights;
end;
function TppReportHeightCalculator.SumTheHeights: Double;
begin
Result := ppFromMMThousandths(FUsedHeight, FReport.Units, pprtVertical,
FReport.Printer);
if (FReport.TitleBand <> nil) then
Result := Result + FReport.TitleBand.Height;
if (FReport.SummaryBand <> nil) then
Result := Result + FReport.SummaryBand.Height;
if (FReport.HeaderBand <> nil) then
Result := Result + FReport.HeaderBand.Height;
if (FReport.Footerband <> nil) then
Result := Result + FReport.FooterBand.Height;
end;
procedure TppReportHeightCalculator.SetVisibleBands(aReport: TppReport;
aVisible: Boolean);
begin
if (aReport.TitleBand <> nil) then
aReport.TitleBand.Visible := aVisible;
if (aReport.SummaryBand <> nil) then
aReport.SummaryBand.Visible := aVisible;
if (aReport.HeaderBand <> nil) then
aReport.HeaderBand.Visible := aVisible;
if (aReport.Footerband <> nil) then
aReport.Footerband.Visible := aVisible;
end;
procedure TppReportHeightCalculator.ReportEndPageHandler(Sender: TObject);
begin
FUsedHeight := FUsedHeight + FDetailStopPosition;
end;
procedure TppReportHeightCalculator.DetailBandAfterPrintHandler(Sender:
TObject);
begin
FDetailStopPosition := FReport.Engine.PrintPosRect.Top;
end;
end.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
Thanks for the Help
Peter
The example you sent worked under RB 6.03 after I ignored all of the
missing properties and I have successfully integrated it into my own code.
Thanks again
Peter