Home Devices

Printing selected pages to a PDF file

edited June 2014 in Devices
Hi,
I cannot figure out how to do this, I've tried using this code (trying to
print pages 4,5 and 6 of my report)

MyReport.DeviceType := 'PDF';
MyReport.AllowPrintToFile := True;
MyReport.TextFileName := 'c:\temp\TR6RBReport.pdf';
MyReport.Print;

with this in the OnBeforePrint vent handler of MyReport
myReport.PrinterDevice.PageSetting := psPageRange;
for i := 4 to 6 do
myReport.PrinterDevice.PageList.Add(IntToStr(i));

but it prints all pages.

I've tried creating a TppPrinterDevice....

fPrinterDevice := TppPrinterDevice.Create(nil);
fPrinterDevice.Publisher := MyReport.Publisher;
MyReport.DeviceType := 'PDF';
MyReport.AllowPrintToFile := True;
MyReport.TextFileName := 'c:\temp\TR6RBReport.pdf';
MyReport.Print;

and this seems to generate nothing at all . What am I doing wrong please?



Comments

  • edited June 2014
    1. You have to used TppReport FileDevice property
    instead PrinterDevice.

    2. You have to used psPageList instead psPageRange.
    psPageRange on this moment can be used in PageStyle
    and TppPrintDialog only.

    3. For assign FileDevice.PageRequest more accurate will be used
    TppReport.OnFileDeviceCreate event.

    4. You code for assign Page numbers correct, and good in this case.
    But sometimes procedure ppTextToPageList can be more useful:

    So, you code have to be something like this:

    procedure MyReportFileDeviceCreate(Sender: TObject);
    begin
    MyReport.FileDevice.PageSetting := psPageList;
    ppTextToPageList('4-6', MyReport.FileDevice.PageList, True);
    end;

    procedure PrintReport;
    begin
    MyReport.DeviceType := 'PDF';
    MyReport.AllowPrintToFile := True;
    MyReport.TextFileName := 'c:\temp\TR6RBReport.pdf';
    MyReport.ShowPrintDialog := False;
    MyReport.Print;
    end;



This discussion has been closed.