How to print a currently displayed record?
Hi,
I have a problem with printing the currently displayed record to PDF.
The way it should work is: User opens print preview (a bit customised,
[Save this doc to PDF] button is added) with a range of records (ie all
day invoices). The user decides to save to PDF a currently viewed one,
presses the button, and voila, the current invoice is saved to a
predefined folder (and optionally emailed to the customer using email
data from database).
I found how to print a page range, but I'd prefer to locate the record
and print to pdf.
Unfortunately, if I set the page range to current:
...
ppDBBase.RangeBegin := rbCurrentRecord;
ppDBBase.RangeEnd := reCurrentRecord;
Rpt.DeviceType := 'PDF';
Rpt.Reset;
Rpt.Print
...
it always prints the first record. I tried to do ppDBBase.Locate first.
The funny thing is it locates the record, and the current record is the
found one until I do Rpt.Print - then it goes to the first one again.
Moreover when I do the same second time it is OK then!
My report is 2-pass with subreports.
I tried also another way:
...
ppDBBase.Locate(IDName, FPageRecordMapping[i], [pploCaseInsensitive]);
ppDBBase.SetBookmark;
Rpt.DeviceType := 'PDF';
Rpt.Reset;
Rpt.Print;
...
procedure TfRptReport.RptAfterPrint(Sender: TObject);
begin
ppDBBase.FreeBookmarks;
end;
...
But then I receive report without details (no subreports data displayed)
on the first run.
BTW, to find the record I use a page-to-record 'mapping procedure', so
knowing the current page nr later on I can locate the record; not sure,
maybe there's some easier way:
...
procedure TfiRptBasicReport.ReportCtrlEndPage(Sender: TObject);
var
i: Integer;
begin
if ReportCtrl.FirstPass and FMapCreation then begin
i := FPageRecordMapping.IndexOf(CurrentRecordID);
if i < 0 then begin
i := FPageRecordMapping.Add(CurrentRecordID,
ReportCtrl.AbsolutePageNo);
...
end;
end;
end;
...
What am I doing wrong? How can I print the currently viewed record?
Thanks,
--
Michal R. Hoffmann
I have a problem with printing the currently displayed record to PDF.
The way it should work is: User opens print preview (a bit customised,
[Save this doc to PDF] button is added) with a range of records (ie all
day invoices). The user decides to save to PDF a currently viewed one,
presses the button, and voila, the current invoice is saved to a
predefined folder (and optionally emailed to the customer using email
data from database).
I found how to print a page range, but I'd prefer to locate the record
and print to pdf.
Unfortunately, if I set the page range to current:
...
ppDBBase.RangeBegin := rbCurrentRecord;
ppDBBase.RangeEnd := reCurrentRecord;
Rpt.DeviceType := 'PDF';
Rpt.Reset;
Rpt.Print
...
it always prints the first record. I tried to do ppDBBase.Locate first.
The funny thing is it locates the record, and the current record is the
found one until I do Rpt.Print - then it goes to the first one again.
Moreover when I do the same second time it is OK then!
My report is 2-pass with subreports.
I tried also another way:
...
ppDBBase.Locate(IDName, FPageRecordMapping[i], [pploCaseInsensitive]);
ppDBBase.SetBookmark;
Rpt.DeviceType := 'PDF';
Rpt.Reset;
Rpt.Print;
...
procedure TfRptReport.RptAfterPrint(Sender: TObject);
begin
ppDBBase.FreeBookmarks;
end;
...
But then I receive report without details (no subreports data displayed)
on the first run.
BTW, to find the record I use a page-to-record 'mapping procedure', so
knowing the current page nr later on I can locate the record; not sure,
maybe there's some easier way:
...
procedure TfiRptBasicReport.ReportCtrlEndPage(Sender: TObject);
var
i: Integer;
begin
if ReportCtrl.FirstPass and FMapCreation then begin
i := FPageRecordMapping.IndexOf(CurrentRecordID);
if i < 0 then begin
i := FPageRecordMapping.Add(CurrentRecordID,
ReportCtrl.AbsolutePageNo);
...
end;
end;
end;
...
What am I doing wrong? How can I print the currently viewed record?
Thanks,
--
Michal R. Hoffmann
This discussion has been closed.
Comments
Rather than trying to control the pipeline, I would suggest altering the
underlying SQL code using AutoSearch or the TdaSQLBuilder object (if you are
using DADE). This allows you to easily adjust the search conditions of any
query connected to a report leaving the pipelines to simply traverse the
data you give them. Then you still will be able to give your users the
ability to export/email the report to PDF by using the built-in email button
of the previewer and/or the print button set to automatically export to PDF.
Examples of using AutoSearch can be found in the \RBuilder\Demos\...
directory and code examples of using the TdaSQLBuilder object can be found
in the RBuilder help.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
I'm afraid you did not understand what I need As far as I understand
the AutoSearch method works actually before displaying the report
(before preview) and/or lets the user to set filters. So it's not
different to setting up the sql filters. But the user has already
filtered results displayed (ie all invoices from a day).
What I need is a possibility to print the record which is currently
previewed. Ie. the user prints preview, scrolls through invoices printed
to the screen and decides to email one of them. Presses the 'Send'
button and the currently previewed record (just one of many, the one
which's page is displayed) is printed to PDF and sent by email or fax or
save to specific folder. For example there's report - 6 invoices:
Invoice Pages
------- -----
i1 1
i2 2-3
i3 4-6
i4 7
i5 8
i6 9-10
I'm on page 5, press 'Send' button and it generates the PDF for invoice
3 only.
Oh, I'm using RB ver. 9 so there's no 'email' button, but it is not an
issue - i just need to generate the PDF. I don't use DADE.
Thanks!
--
Michal R. Hoffmann
Thanks for the clarification.
There is no built-in way to accomplish this in ReportBuilder however it
should be fairly easy to do yourself. For instance, if each invoice is in
its own report group, you can check the group break value when a user
selects to print that invoice. Then you could export the report to PDF
using the break value as a search condition in your dataset so only that
invoice will print. It may be easier to keep the exported report completely
separate from the report the user is previewing.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Thanks for help - actually I mixed both approaches and it works for me
now. My fault was I thought AutoSearch could be used with GUI dialog only.
--
Regards,
Michal R. Hoffmann
* Nico Cizik (Digital Metaphors) wrote, On 15/05/2007 20:40: