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

Printing from dataset on multiple .rtm files

edited August 2012 in General
Hi

I wish to loop through a dataset and print the contents onto different .rtm
templates. After the first record I wish to supress the Print Dialog for
subsequent pages and re use the print settings for the first page.

The first page prints OK but when trying to print (*2 below) the second page
I get a blank dialog box displayed with the caption 'Printing' and a Cancel
button - at that point the application just hangs.

In another part of my application I use a similar technique and it works
exceptionally well so I cannot understand why, in this case, the 2nd page
print information is blank an just hangs

Do you have any ideas?

Thanks for your patience.

Philip L Jackson

My code is something like...


private
printerStream:TMemoryStream;
bFirstPage :Boolean;

The control procedure is...
try
printerStream := TMemoryStream.create;
DiaryTable.First;
for j := 1 to DiaryTable.recorcount do
begin
if j = 1 then bFirstPage := TRUE else bFirstPage
:= FALSE;
CustomService;
DiaryTable.Next;
end;
end;
finally
printerStream.free;
end;


CustomService is....


with ppReport1 do
begin

Template.FileName := OpenCal.RptDirectory + '\Service\'+
DiaryTable.FieldByName('SERVICE_SCHED').AsString ;

Template.LoadFromFile;

if not bFirstPage then
begin
ShowPrintDialog := FALSE;
printerStream.Position := 0;
PrinterSetup.PrinterName := MyPrinter;
PrinterSetup.LoadDeviceSettingsFromStream(printerStream);
end;
....setup auto search.....

ShowAutoSearchDialog := FALSE;
ppviewer1.RegenerateReport;


if bFirstPage then
begin
ppviewer1.Print;
PrinterSetup.SaveDeviceSettingsToStream (printerStream);
MyPrinter := ppReport1.Printer.PrinterName;
end else
begin
ppReport1.ShowPrintDialog := FALSE;
ppviewer1.Print; *2 problem is
here
end;

end;//end of procedure

Comments

  • edited August 2012
    Hi Philip,

    Which version of ReportBuilder are you using?

    How is this section of your application different from the section that
    functions correctly?

    If you are using RB 14, I would be a little concerned about your call to
    Viewer.RegenerateReport (which essentially re-prints the report), then
    Report.Print so soon after. RB 14 prints the report in a background
    thread so the call to Report.Print will not wait for the Regeneration to
    finish and could cause issues.

    If this RegenerateReport call is necessary, try implementing the
    Viewer.OnPrintStateChange event to determine when it is no longer busy
    and it is safe to call Report.Print.

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2012
    Hi

    Thanks for your reply - sorry I did not say but I am using RB 14.06

    I have managed to create a small application which demonstrates the issue I
    am having and will email this to support.

    Thanks for your patience.

    Philip L Jackson

  • edited August 2012
    Hi

    Using the previously mentioned test example I have found that, as you
    suggest the RegenerateReport was causing the issue, so I have not sent the
    program by email.

    I have resolved the first part of my problem but there are still issues of a
    similar nature when creating pdf documents and emailing these.

    Can you point me to examples of how to use the Viewer.OnPrintStateChange to
    see if I can resolve my pdf/email problems?

    Thanks in advance.

    Philip L Jackson

    Do you have any examples

  • edited August 2012
    Hi Philip,

    Simply implement the Viewer.OnPrintStateChange event and check the
    Viewer.Busy property inside.

    If the viewer is not busy, it is then ok to preform report actions that
    require the engine (printing, exporting, re-generation).

    Below is some simple pseudo-code:

    procedure MyClass.Execute;
    begin
    Report.Print;

    if not(Viewer.Busy) then
    ExportToPDF
    else
    WaitingToExport := True;

    end;

    procedure MyClass.ExportToPDF;
    begin
    Report.DeviceType := 'PDF';
    Report.Print;

    end;

    procedure MyClass.ViewerPrintStateChange(Sender: TObject);
    begin
    if not(Viewer.Busy) and (WaitingToExport) then
    begin
    WaitingToExport := False;
    ExportToPDF;

    end;

    end;

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited August 2012
    Hi

    Still having trouble so I have sent over a small example to illustrate my
    problem.

    Any advice you can offer would be most gratefully appreciated.

    Best Wishes

    Philip L Jackson

This discussion has been closed.