How to display the total number of pages in PL/PDF 5

Applies to: PL/PDF 5.x

In earlier PL/PDF versions, the {cp} and {nb} aliases could be used to display the current page number and the total number of pages:

'{cp}/{nb}'

In PL/PDF 5, use the following functions instead:

  • plpdf.getCurrPageNum – returns the current page number

  • plpdf.getNumOfPages – returns the total number of pages

The equivalent PL/PDF 5 expression is:

to_char(plpdf.getCurrPageNum) || '/' ||
to_char(plpdf.getNumOfPages())

Important

plpdf.getNumOfPages can only be used inside a registered header or footer procedure. It should not be called directly while generating the main document content.

Example footer procedure

procedure document_footer is
begin
  plpdf.SetPrintFont(
    p_family => 'Arial',
    p_style  => 'I',
    p_size   => 8
  );

  plpdf_cell.PrintCell(
    p_width  => null,
    p_height => 10,
    p_text   => to_char(plpdf.getCurrPageNum) || '/' ||
                to_char(plpdf.getNumOfPages()),
    p_ln     => plpdf_const.beside,
    p_align  => 'C'
  );
end;

Register the footer procedure before creating the document pages:

plpdf.SetFooterProcName(
  p_proc_name => 'MY_REPORT.DOCUMENT_FOOTER',
  p_height    => 10
);

The generated footer will display page numbers in the following format:

1/5
2/5
3/5

Replace MY_REPORT.DOCUMENT_FOOTER with the actual package and procedure name used by your application.

The complete implementation can also be found in the supplied PL/PDF examples under:

PLSQL/PDF/Basic5/BasicExamples.sql

See the PageNumber and footer2 procedures.

 

Article Details