AliasNbPages: Handling page numbering   [ 43 ]

Description

Defines an alias which will be dynamically and automatically replaced by the total number of pages of the PDF document when it will be created. This function is practical when it is required to have a page footer or header containing something like like: "Ith page among N", while N is not known precisely in advance when processing starts. It takes one parameter which is a character string which will be replaced.  It is advised to pick up a string pattern which is unlikely to be found in document content.  For example: "£££££".

C calling syntax
void AliasNbPages (char *alias)
Cobol calling syntax
Call "ALiasNbPages" using by value ALIAS.
C sample code
#include   "fpdf.h"

static char   f_ini ??(??) = ??< "ini??/??/demofpdf.ini" ??>;
static char   f_out ??(??) = ??< "pdf??/??/demo_h.pdf" ??>;
static char   bufr ??(128??), fieldname ??(8+1??);

/* ----------------------------------------------------------------- */

int  main (int argc, char *argv [])

??<
int    ii, jj, formnumb;

NewPdfy (f_ini, 10);
AliasNbPages ("#####");
formnumb = SetForm ("demo_h");

for (ii = 0; ii < 10; ii ++)
     ??<
     AddPage ("P");
     InclForm (formnumb);
     sprintf (bufr, "Page #%d / #####", ii + 1);
     ApplyTextProp ("PAGENUMB", bufr);
     for (jj = 0; jj < 18; jj ++)
         ??<
         sprintf (fieldname, "FIELD%03d", jj);
         sprintf (bufr, "Field #%d Value of page %d", jj, ii + 1);
         ApplyTextProp (fieldname, bufr);
         ??>
     ??>

FlushPdf (f_out, 2, "CUSTZZ", "demo_h");
??>
Description of sample code
This programs illustrates the power of forms related functions available in FPDF4ZOS.  It opens a PDF context, and imports a form and loops on 10 pages where this form is included.  In the loop, keeping in mind that this form includes 18+1 anchors, there is a scond loop in order ti fill all these fields with dummy data.

The following functions are used in this piece:
- NewPdfy()       -->  Initialisation of a pdf context
- AddPage()       -->  As it says
- SetLineWidth()  -->  Instruct that PDF is to be protected at user and owner levels
- SetDrawColor()  -->  Set the color of lines to be drawn
- SetFillColor()  -->  Set the color of area to be filled
- SetFont()       -->  Set current font
- SetForm()       -->  Specify a form to be included
- InclForm()      -->  Include a form within current page
- ApplyTextProp() -->  Display a piece of text with an anchor properties (Font, Color, Position)
- AliasNbPages()  -->  Specify an Alias for document total number of pages
- FlushPdf()      -->  Output PDF file taking into account all the instructions invoked since context initialization
See sample source code in 'C' as well as PDF execution result  -  NB: For encrypted PDFs, user password is USER-PSWD