Problem: Report Builder output converted to text file (has more than 1 page) and then sent to print
Hello,
I am experiencing the lack of a page break when printing more than 1 invoice
or an invoice than is more than 1 page after the report has been converted
to a file and then sent to a "generic text printer" for fast text printing.
When these files are sent to the printer, the printer prints page 1 and 6 -
8 lines of what
should be the next page on the same piece of paper and stops. Page 2 of 2
(as in rpt2180karen.txt) never gets printed and the 2nd invoice (#2222) of
rpt1679karen.txt does not get printed other than the 6-8 lines at the bottom
of the first invoice's (#2221) page.
Your assistance will be greatly appreciated.
Karen
code showing conversion of report into a file, reading and sending to a
printer:
procedure Tform2180.Rpt2180r1BeforePrint(Sender: TObject);
var
lDevice : TppReportTextFileDevice;
begin
inherited;
if (rpt2180r1.Tag = 2) then
begin
// Fills in a suggested textfile name. If user changes it in the print
// dialog box, it is captured in the procedure
Rpt1679r1PrintingComplete.
rpt2180r1.DeviceType := 'ReportTextFile';
rpt2180r1.TextFileName := ExtractFilePath (Application.ExeName) +
'Rpt2180' + AaGetUserName + '.txt';
GetReport;
// Original value was screen, ppProd changes it to printer when
// the user clicks the File|print or printer icon. We need it to be
// ReportTextFile to create a text file for printing to dot matrix
printer.
if (rpt2180r1.ModalPreview = True) then
rpt2180r1.DeviceType := 'ReportTextFile';
if (rpt2180r1.FileDevice <> nil) and
(rpt2180r1.FileDevice is TppReportTextFileDevice) then
begin
lDevice := TppReportTextFileDevice(rpt2180r1.FileDevice);
lDevice.CharacterGrid(120,66);
end;
end;
end;
code inside of ProcessReport:
// If user clicks on cancel, code below will prevent processing
// the next 6 lines of code to print, (rename when testing)
// & delete file.
if not MyForm2180.PrintJobCanceled and MyForm2180.FPreviewClose
then
begin
PrintInvoiceTextFileToPrinter(Myform2180.Rpt2180r1.TextFileName);
end;
....
etc.
Note: when rpt2180Karen.txt file was created and loaded into
lsLines:TStringList, the
total count for lsLines show a total of 131.
procedure Tdm2180.PrintInvoiceTextFileToPrinter(aFileName: String);
var
i : integer;
lsLines: TStringList;
begin
lsLines := TStringList.Create;
try
lsLines.LoadFromFile(aFileName);
SetAUsersPrinter('2180', Form2180.Rpt2180r1);
// Scrolls through the users' printerlist and sets the printerindex to
the
// printer that was set in Report Settings. Without this call, the file
// would be printed to the current windows default printer.
Printer.PrinterIndex :=
GetTextPrinter(Form2180.Rpt2180r1.PrinterSetup.PrinterName);
with Printer do
begin
BeginDoc; // starts
printing
for i := 0 to lsLines.Count-1 do
Canvas.Textout(0,5 +
(i * Canvas.TextHeight(lsLines.Strings[i])), lsLines[i]);
Enddoc; // ends printing
end;
finally
lsLines.Free;
end;
end;
procedure Tdm2180.SetAUsersPrinter (PrinterTag:String; Rept:TppReport);
var
PrinterName: String;
Copies: Integer;
Duplex: TppDuplexType;
PaperHeight: Single;
MarginTop: Single;
MarginLeft: Single;
MarginBottom: single;
MarginRight: single;
PrintCompany: Boolean;
i : integer;
begin
AaGetPrinterDefaults(PrinterTag, PrinterName, Copies, Duplex,
PaperHeight, MarginTop, MarginLeft, MarginBottom,
MarginRight,
PrintCompany);
Rept.PrinterSetup.PrinterName := PrinterName;
end;
function Tdm2180.GetTextPrinter(aPrinterName : string) : integer;
var
PrinterList: TStringList;
i : integer;
s : string;
begin
Result := 0; // initialize
PrinterList := TStringList.Create;
PrinterList.Assign(Printer.Printers);
for i := 0 to PrinterList.Count-1 do
begin
s := PrinterList[i];
if (pos (aPrinterName, s) > 0) then
begin
Result := i;
break;
end;
end;
end;
I am experiencing the lack of a page break when printing more than 1 invoice
or an invoice than is more than 1 page after the report has been converted
to a file and then sent to a "generic text printer" for fast text printing.
When these files are sent to the printer, the printer prints page 1 and 6 -
8 lines of what
should be the next page on the same piece of paper and stops. Page 2 of 2
(as in rpt2180karen.txt) never gets printed and the 2nd invoice (#2222) of
rpt1679karen.txt does not get printed other than the 6-8 lines at the bottom
of the first invoice's (#2221) page.
Your assistance will be greatly appreciated.
Karen
code showing conversion of report into a file, reading and sending to a
printer:
procedure Tform2180.Rpt2180r1BeforePrint(Sender: TObject);
var
lDevice : TppReportTextFileDevice;
begin
inherited;
if (rpt2180r1.Tag = 2) then
begin
// Fills in a suggested textfile name. If user changes it in the print
// dialog box, it is captured in the procedure
Rpt1679r1PrintingComplete.
rpt2180r1.DeviceType := 'ReportTextFile';
rpt2180r1.TextFileName := ExtractFilePath (Application.ExeName) +
'Rpt2180' + AaGetUserName + '.txt';
GetReport;
// Original value was screen, ppProd changes it to printer when
// the user clicks the File|print or printer icon. We need it to be
// ReportTextFile to create a text file for printing to dot matrix
printer.
if (rpt2180r1.ModalPreview = True) then
rpt2180r1.DeviceType := 'ReportTextFile';
if (rpt2180r1.FileDevice <> nil) and
(rpt2180r1.FileDevice is TppReportTextFileDevice) then
begin
lDevice := TppReportTextFileDevice(rpt2180r1.FileDevice);
lDevice.CharacterGrid(120,66);
end;
end;
end;
code inside of ProcessReport:
// If user clicks on cancel, code below will prevent processing
// the next 6 lines of code to print, (rename when testing)
// & delete file.
if not MyForm2180.PrintJobCanceled and MyForm2180.FPreviewClose
then
begin
PrintInvoiceTextFileToPrinter(Myform2180.Rpt2180r1.TextFileName);
end;
....
etc.
Note: when rpt2180Karen.txt file was created and loaded into
lsLines:TStringList, the
total count for lsLines show a total of 131.
procedure Tdm2180.PrintInvoiceTextFileToPrinter(aFileName: String);
var
i : integer;
lsLines: TStringList;
begin
lsLines := TStringList.Create;
try
lsLines.LoadFromFile(aFileName);
SetAUsersPrinter('2180', Form2180.Rpt2180r1);
// Scrolls through the users' printerlist and sets the printerindex to
the
// printer that was set in Report Settings. Without this call, the file
// would be printed to the current windows default printer.
Printer.PrinterIndex :=
GetTextPrinter(Form2180.Rpt2180r1.PrinterSetup.PrinterName);
with Printer do
begin
BeginDoc; // starts
printing
for i := 0 to lsLines.Count-1 do
Canvas.Textout(0,5 +
(i * Canvas.TextHeight(lsLines.Strings[i])), lsLines[i]);
Enddoc; // ends printing
end;
finally
lsLines.Free;
end;
end;
procedure Tdm2180.SetAUsersPrinter (PrinterTag:String; Rept:TppReport);
var
PrinterName: String;
Copies: Integer;
Duplex: TppDuplexType;
PaperHeight: Single;
MarginTop: Single;
MarginLeft: Single;
MarginBottom: single;
MarginRight: single;
PrintCompany: Boolean;
i : integer;
begin
AaGetPrinterDefaults(PrinterTag, PrinterName, Copies, Duplex,
PaperHeight, MarginTop, MarginLeft, MarginBottom,
MarginRight,
PrintCompany);
Rept.PrinterSetup.PrinterName := PrinterName;
end;
function Tdm2180.GetTextPrinter(aPrinterName : string) : integer;
var
PrinterList: TStringList;
i : integer;
s : string;
begin
Result := 0; // initialize
PrinterList := TStringList.Create;
PrinterList.Assign(Printer.Printers);
for i := 0 to PrinterList.Count-1 do
begin
s := PrinterList[i];
if (pos (aPrinterName, s) > 0) then
begin
Result := i;
break;
end;
end;
end;
This discussion has been closed.
Comments
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com