Headers and Footers

Start page  Previous page  Next page

 

n2pdf supports the creation of headers and footers for the PDF file. A header or footer can consist of plain text or the content of a RichText field. A header or footer can also be defined based on the content of a given page and will enclose the main text of the PDF file.

 

In n2pdf headers and footers are defined using the function N2PDFAddContent or N2PDFAddRTContent, whereby when used with these functions the constant

 

N2PDFVALUE_CONTENT_HEADER

 

specifies the header and

 

N2PDFVALUE_CONTENT_FOOTER

 

specifies the footer (see the parameter <ContentType> under functions).

 

The page on which the header, footer and/or inserted content is to appear can be specified using an additional constant (see the parameter <ContentOption> under the functions listed above). Here are the options available for setting headers and footers using the above-named functions:

 

N2PDFVALUE_HF_ALL_PAGES

On all pages

N2PDFVALUE_HF_FIRST_PAGE

On first page only

N2PDFVALUE_HF_LAST_PAGE

On last page only

N2PDFVALUE_HF_EVEN_PAGES

On all even pages

N2PDFVALUE_HF_ODD_PAGES

On all odd pages

N2PDFVALUE_HF_NOT_FIRST_LAST_PAGES

On all pages except the first and last page

 

Header on footer on individual pages

As well as using the constants named above, you can also set a header or footer (Parameter <ContentType>) selectively for a particular page. In this case, simply pass the desired page number as a negative value in the parameter <ContentOption>.

 

Empty headers and footers

If you want to delete the content of a header or footer, simply pass an empty text ("") as the value for the header or footer.

 

 

Example:

 

The following calls are needed to specify different headers for the even and odd pages:

Call N2PDFAddContent ( JobID, N2PDFVALUE_CONTENT_HEADER,_

N2PDFVALUE_HF_EVEN_PAGES, "Even pages" )

 

Call N2PDFAddContent ( JobID, N2PDFVALUE_CONTENT_HEADER,_

N2PDFVALUE_HF_ODD_PAGES, "Odd pages" )

 

Header for a certain page:

Call N2PDFAddContent ( JobID, N2PDFVALUE_CONTENT_HEADER,_

-5, "Header for page 5" )

 

The same footer on all pages except for page 5 which has no footer at all:

Call N2PDFAddContent ( JobID, N2PDFVALUE_CONTENT_FOOTER,_

N2PDFVALUE_HF_ALL_PAGES, "All pages" )

 

Call N2PDFAddContent ( JobID, N2PDFVALUE_CONTENT_FOOTER, -5, "" )

 

112

The use of headers and footers is shown in the sample applicationHeader and Footer".

 

 

112

Please keep in mind that a cue for a specific page can only be made one time. If you call up the same page more than once, e.g. N2PDFVALUE_HF_ODD_PAGES, the last value set will be the one that is applied. Creating a header or footer for a specific page replaces the entire content of the header or footer and does not attach its content to any text that might already exist.

 

 

Plain text to be added a header or footer will be inserted using the currently selected text template.

 

112

For serial letters only N2PDFVALUE_HF_ALL_PAGES may be used to define headers and footers. Individual pages cannot be identified in serial letters.

 

 

Chapter headings in headers and footers

If the title of the current chapter is to be shown in a header or footer, e.g. in books, this can be done using the constant "[TOC]" (se document Constants"). The constant "[TOC]" is replaced with the current chapter text, which was defined in the main text with "[TOC:x]" (see document "Table of contents").

 

 

clip0052

 

 

For this constant to be available in headers and footers, the option N2PDFOPTION_TOC_HF_VARIABLE must be set to the value N2PDFVALUE_TRUE:

 

Call N2PDFSetOption ( JobID, N2PDFOPTION_TOC_HF_VARIABLE, N2PDFVALUE_TRUE, "" )

 

112

The "[TOC]" constant can only be used in headers and footers.

 

112

It can happen that the insertion of the chapter text (long heading) may cause the content of the page to be shifted, so that the chapter changes page. In this case the content of the "TOC" constants may possibly not agree with the page of the chapter heading. This can only be prevented if the chapter headings always begin on a new page.

 

It is also possible to specify whether the chapter numbering is part of the constant. If the option N2PDFOPTION_TOC_HF_VARIABLE_WITH_LEVEL is set to N2PDFVALUE_TRUE, then the numbering is included (see image); for N2PDFVALUE_FALSE, it is not.

 

Do not use chapter numbering:

Call N2PDFSetOption ( JobID, N2PDFOPTION_TOC_HF_VARIABLE_WITH_LEVEL, N2PDFVALUE_FALSE, "" )

 

With very many levels of chapter numbering, it is possible that only a certain depth of chapter/section headings is wanted, e.g. only main chapters at the first level. The option N2PDFOPTION_TOC_HF_VARIABLE_MAX_LEVEL can be used to decide the max. level. The parameter is set according to the numbering of "[TOC:x]".

 

Use only chapter headings of the first level:

Call N2PDFSetOption ( JobID, N2PDFOPTION_TOC_HF_VARIABLE_MAX_LEVEL, "1", "" )

 

112

If there is more that one chapter heading on a page, only the first heading is used.