accurate way to dynamically calculate paper height
Greetings,
I am writing an application that is using Report Builder to print receipts
for point of sale software. Because of this, I do not know the paper size
at design time and I'm trying to see it at run time accurately. Through
searching archived posts I have found how to change the paper height in the
OnStartPage event using TppReport.Engine.Page.PrinterSetup.PaperHeight. I
decided to iterate through all of the bands of the TppReport object and add
up the spHeight of each band. For the detail band, I multiply the number of
records in my query by the spHeight of the detail band. The problem is, the
PrintHeight for all of my bands are set to phDynamic (as they should be), so
the height is not the printed height, but rather, the height that I have set
at design time.
My code in the OnStartPage event looks like this...
procedure TReceiptDM.repReceiptSerialStartPage(Sender: TObject);
var
i, paperHeight : Integer;
begin
paperHeight := 0;
for i := 0 to fReport.BandCount - 1 do
begin
if fReport.Bands[i].Name = 'ppDetailBand1' then
begin
paperHeight := paperHeight + (fReport.Bands[i].spHeight *
fQuery.RecordCount);
end
else
begin
paperHeight := paperHeight + fReport.Bands[i].spHeight;
end;
end;
fReport.Engine.Page.PrinterSetup.PaperHeight := paperHeight;
end;
However, in my application, I have some regions in the report which can be
made visible or not visible within the application, and (of course) the
paper height stays the same, leaving me with a lot of room down at the
bottom of the page.
Is there a better approach to figuring out the paperHeight at run time?
Thank you,
Kevin Steffensen
I am writing an application that is using Report Builder to print receipts
for point of sale software. Because of this, I do not know the paper size
at design time and I'm trying to see it at run time accurately. Through
searching archived posts I have found how to change the paper height in the
OnStartPage event using TppReport.Engine.Page.PrinterSetup.PaperHeight. I
decided to iterate through all of the bands of the TppReport object and add
up the spHeight of each band. For the detail band, I multiply the number of
records in my query by the spHeight of the detail band. The problem is, the
PrintHeight for all of my bands are set to phDynamic (as they should be), so
the height is not the printed height, but rather, the height that I have set
at design time.
My code in the OnStartPage event looks like this...
procedure TReceiptDM.repReceiptSerialStartPage(Sender: TObject);
var
i, paperHeight : Integer;
begin
paperHeight := 0;
for i := 0 to fReport.BandCount - 1 do
begin
if fReport.Bands[i].Name = 'ppDetailBand1' then
begin
paperHeight := paperHeight + (fReport.Bands[i].spHeight *
fQuery.RecordCount);
end
else
begin
paperHeight := paperHeight + fReport.Bands[i].spHeight;
end;
end;
fReport.Engine.Page.PrinterSetup.PaperHeight := paperHeight;
end;
However, in my application, I have some regions in the report which can be
made visible or not visible within the application, and (of course) the
paper height stays the same, leaving me with a lot of room down at the
bottom of the page.
Is there a better approach to figuring out the paperHeight at run time?
Thank you,
Kevin Steffensen
This discussion has been closed.
Comments
ReportBuilder will calculate the space needed for each page during the first
pass of the report. You may try setting your report's PassSetting to
psTwoPass, then inside the OnStartPage, check the Report.SecondPass before
check the page length.
Also, you may want to take a look at the following article on printing to
continuous paper. It may be of some help.
----------------------------------------------------
Article: Printing to Continuous Paper
----------------------------------------------------
1. Layout
For continuous printing (for example a receipt) use Title/Summary and
removing the Header/Footer. Set the PrintHeight of each to phDynamic. Layout
the DetailBand to print a single line item. Set the margins to 0 or to the
smallest that the printer driver will support (some printers have an
unprintable area).
With this configuration The Report will generate a Title followed by a
variable number of Detail bands that span pages if needed, and then finally
print a Summary at the end.
2. Pagination
a. dtPrinter
Some printer drivers have a continuous paper size setting. If not then try
setting the paper size to be very small - perhaps the size of the tallest
band in the layout. Or try setting the page height to be the size of a
detail band. Note that some printer drivers will only accept page sizes
within a certain range of paper sizes.
b. dtReportTextFile
With the above layout, the report text file will generate the page breaks
properly, however the device will fill up a page with blank lines. You can
control the number of lines per page by configuring the CharacterGrid
property in the Report.BeforePrint event:
example:
procedure TForm1.ppReport1BeforePrint(Sender: TObject);
var
lDevice: TppReportTextFileDevice;
begin
if (ppReport1.FileDevice <> nil) and (ppReport1.FileDevice is
TppReportTextFileDevice)then
begin
lDevice := TppReportTextFileDevice(ppReport1.FileDevice);
{120 characters per line, 66 lines per page}
lDevice.CharacterGrid(120, 66);
end;
end;
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Report Builder 6.03
Delphi 6
Windows XP