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

How to send a report to printer and save as pdf with no print Dialog

I need to send a report to a printer and to save a copy as pdf to the fileserver. I have used two different options and neither does exactly what i want. Here they are:

1.
FPDFDevice := TppPDFDevice.Create(nil);
FPDFDevice.Publisher := ppReportCombined.Publisher;
FPDFDevice.FileName := fEstablishment + '.PDF';
ppReportCombined.Print;
//this fails because I have not used a print dialog
FPDFDevice.PageRequest :=TppPageRequest(ppReportCombined.PrintDialog.PageRequest);

this saves the file to the share and it looks great, but i get no printed ite

2. ppReportCombined.DeviceType := 'Printer';
ppReportCombined.ShowPrintDialog := false;
FDevice := TppDevice.Create(self);
FDevice.Publisher := ppReportCombined.Publisher;
FDevice.OnPageReceive := ehDevicePageReceive;
ppReportCombined.AllowPrintToFile := true;
ppReportCombined.Print;
FDevice.Free;

procedure TfrmEnforce.ehDevicePageReceive(Sender, aPage: TObject);
var
lPage: TppPage;
lFileDevice: TppPDFDevice;
begin

lPage := TppPage(aPage);

lFileDevice := TppPDFDevice.Create(self);

try

lFileDevice.FileName := fEstablishment +'.pdf';
lFileDevice.StartJob;
lFileDevice.ReceivePage(lPage);
lFileDevice.EndJob;

finally
lFileDevice.Free;

end;

end;

this prints perfectly but saves only the second page of my report.


Help?

thanks

Jim



Comments

Sign In or Register to comment.