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

PDF - Printing just certain pages to PDF without user input

edited January 2009 in Devices
Hi,

I am using RB V10 and Delphi 2007. Is there a way to use the inbuilt PDF
writer to print only a subest of pages to PDF. I have a 6 page document
where I would like Page 1 to go to one PDF document, Page 2 to another and
pages 3-6 to a third PDF document. I would like this to happen
automatically when the user chooses to print to PDF.

Thanks

Alex

Comments

  • edited January 2009
    Hi Alex,

    Take a look at the following rbWiki article on sending each page as a new
    PDF file. With some simple alterations, you should be able to get the
    result you are after.

    http://www.digital-metaphors.com/rbWiki/Output/PDF/How_To...Send_Each_Page_as_a_PDF

    --
    Regards,

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

    Best Regards,

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

    Ive tried a few things with that example to get it to print page 1 to 1 pdf,
    page 2 to another pdf and pages 3-6 to a third pdf. Here is an example of
    what I have tried but it falls over. Do I keep the job open when wanting to
    priint multiple pages? Thats what I am trying but what I get on the third
    pdf creation is that I cannot create the file because it is being used by
    another process. Then the program aborts and then none of the 3 pdfs can be
    opened. Ideas appreciated.

    Alex

    procedure TfrmPrint.ehDevicePageReceive(Sender, aPage: TObject);
    var
    lPage: TppPage;
    pageNbr: Integer;
    begin


    lPage := TppPage(aPage);
    pageNbr := lPage.AbsolutePageNo;
    case pageNbr of
    1: begin
    lFileDevice := TppPDFDevice.Create(self);
    lFileDevice.FileName := 'e:\' + cbRegistration.Text;
    lFileDevice.StartJob;
    lFileDevice.ReceivePage(lPage);
    lFileDevice.EndJob;
    lFileDevice.Free;
    end;
    2: begin
    lFileDevice := TppPDFDevice.Create(self);
    lFileDevice.FileName := 'e:\' + cbWelcome.Text;
    lFileDevice.StartJob;
    lFileDevice.ReceivePage(lPage);
    lFileDevice.EndJob;
    lFileDevice.Free;
    end;
    3: begin
    lFileDevice := TppPDFDevice.Create(self);
    lFileDevice.FileName := 'e:\' + cbLM.Text;
    lFileDevice.StartJob;
    lFileDevice.ReceivePage(lPage);
    end;
    4,5:
    begin
    lFileDevice.ReceivePage(lPage);
    end;
    6: begin
    lFileDevice.ReceivePage(lPage);
    lFileDevice.EndJob;
    lFileDevice.Free;
    end;
    end;
    end;

  • edited January 2009
    Hi Alex,

    Sorry about that. I hadn't taken a look at this example in a while. For
    each page, a "message" page is sent with preliminary information. This was
    causing the StartJob for page 3 to be called twice which caused the AV. If
    you place a small condition at the beginning of the Page Receive event
    checking for a "message" page the problem should be solved.

    procedure TfrmPrint.ehDevicePageReceive(Sender, aPage: TObject);
    var
    lPage: TppPage;
    pageNbr: Integer;
    begin

    if FDevice.IsMessagePage then exit;

    lPage := TppPage(aPage);
    pageNbr := lPage.AbsolutePageNo;
    case pageNbr of

    ...


    --
    Regards,

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited January 2009
    Worked perfectly thanks for that.

    Just quickly what information does MessagePage give you? Where would that
    be documented?

    Thanks

    Alex

  • edited January 2009
    The message pages hold the status information while a report is printing.
    For instance, when you see a message saying "accessing data" or "printing
    page x of x".

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