Home Devices

Page break and printing more than 1 page problem

edited September 2005 in Devices
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.

I have enclosed 2 small report files that were created. 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;

Comments

  • edited September 2005
    Hi Karen,

    For future reference, please send all attachment to
    support@digital-metaphors.com.

    If you trace through the code in the PrintInvoiceTextFileToPrinter routine
    are you able to see why lines from the second page are printing to the
    first? I'm a bit unclear about what is happening here. Are you creating a
    text file for each separate page or is this just one large text file? Note
    that once you export to Text, all pagination information is lost and the
    text file exported will print as-is (i.e. if there's room for more lines on
    the first page, they will get printed).

    --
    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 responding.

    I am creating a text file for the entire report which is several pages.
    I did not know that I would be losing all of my pagination and as a result,
    part of the second page would be printed on the first page.

    Also, the additional problem that I am experiencing is that the remaining
    lines of page 2 (that were not printed on page 1) is not getting printed at
    all. I assume the following line of code
    in
    procedure Tdm2180.PrintInvoiceTextFileToPrinter(aFileName: String);

    with Printer do



    (Canvas.Textout....) prevents more than 1 page from being printed.

    How do I fix it so that I can print multiple pages? You mentioned the
    possibility of creating a text file for each separate page?

    Your assistance is greatly appreciated.

    Karen



  • edited September 2005
    Hi Karen,

    Two options...

    1. Take a look at the following example on how to print each page to a
    different text file. This way you could use your current code and print
    each file after it is generated.

    http://www.digital-metaphors.com/tips/SendEachPageAsNewFile.zip

    2. I believe the TPrinter object allows the printing of multiple pages
    however we have little to no experience with this. It may be documented in
    the Delphi help.

    --
    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 your assistance and the example. I appreciate it very much!!!!
    :)

    When opening the example project in delphi, I do get the following error.
    How do I resolve?

    Error reading ppReport1.OutlineSettings.CreateNode:
    Property OutlineSettings does not exist.

    (I am using Delphi 6.0; Build 6.240 and Report Builder Professional 6.03)


    Karen


  • edited September 2005
    Hi Karen,

    This error should not affect the way the example runs (the outline was added
    for RB 7 and the example was created in RB 9). You should just be able to
    select the "ignore" option when you get this error and still run
    successfully.

    Take a look at the code in the example on how to create a file device for
    each page request from a "dummy" TppDevice object. If all else fails, this
    should be easily reproducible in Delphi 6, RB 6.03.

    --
    Regards,

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

    Best Regards,

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

    Do you have a suggestion on how to "rotate" through all of the page files
    that are created from sending each page as a file?

    Your suggestions are most appreciated.

    Thanks,

    Karen

  • edited October 2005
    Hi Nico,

    I am experiencing an "AV error" when running the example report.

    This "AV error" happens when:
    1) I have added my own report to the example and run it.
    2) Extracted the code and placed it in my current project and run it.

    Your assistance in resolving will be greatly appreciated.

    Thanks,
    Karen.



  • edited October 2005
    Hi Karen,

    Once you have created all your text files, you can loop through each one and
    print it using the method you were using to print the single text file. I
    would try streaming each file then outputing the text to the Printer.Canvas
    as you did before. I also believe the TStrings object has a LoadFromFile
    routine that may be of some use.

    --
    Regards,

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

    Best Regards,

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

    If you set your debugger to stop on exceptions and add the
    \RBuilder\Source\... directory, where is the AV occuring?

    --
    Regards,

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

    Best Regards,

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

    In the procedure: TppReport.PrintToDevices;

    at:
    inherited PrintToDevices;



  • edited October 2005
    If possible, please send a small example demonstrating this behavior to
    support@digital-metaphors.com in .zip format and I'll take a look at it for
    you.

    --
    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.