Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RTF number of pages Page x of y

Tags:

rtf

Not sure if this is even possible but I am trying to save text via a plain text output to an RTF with special coding.

I have everything working except the total number of pages.

I want it to say "Page x of y", the bottom of each page to say "Page 1 of 3" for example, but I can't find the correct code for the total page number.

Some people said use \nofpages but the source says the use of \nofpagesN is the specify the number of pages in the document. Is there a formula or something I can use or maybe a way to put the last page number? Here is an example of my code, if you put it into an rtf file via notepad then save and open in wordpad or word you will see what I mean:

{\rtf1\pagestart1 {\header\brdrt\brdrth\ql\b Name:  \b0LAST, FIRST \par\b DOB:  \b0 1979/11/03 \par\b Service Date/Time:  \b0 2012/03/06 00:49:00 \par\b MRN:  \b0 XXXXXX \par\b Order Date/Time:  \b0 2012/03/05 01:14:00 \par\b Study ID:  \b0 } \par{\footer\pard\brdrt\brdrs\qc\fs16\b\ul CONFIDENTIALITY NOTICE \par\par\pard\brdrt\brdrs\keepn\ql\fs20 Date: \chdate\par\keepn\qc\fs20 Page \chpgn  of \nofpages\par}\b Study ID:  \b0 000000000000 \par\pard\brdrb\brdrth A bunch of text to make up more than one page. \par \par \par {\footnote\pard\b Some stuff in the footer \b0\par}}
like image 644
Opy Avatar asked Mar 07 '12 14:03

Opy


People also ask

How to get page numbers in sas?

SAS itself does not have any functions to do real page count. Instead, SAS borrows Microsoft Word processors to compute those numbers and put them in the final output by using TITLE or FOOTNOTE statements with “{page {\field{\fldinst{page}}} of {\field{\fldinst{numpages}}}}” or “Page ~{thispage} of ~{lastpage}”.

How do I add page numbers to Rich Text Format?

Press the CTRL+F9 key combination to insert a field. A pair of braces appears, indicating the code range of the field. Type in 'page' to denote a page number or a 'numpages', for the total number of pages in the document. Right-click the field and select 'Update Field' command in the context menu.


3 Answers

Code:

This is page \chpgn  of {\field{\*\fldinst  NUMPAGES }}, wonderful!

produces output (fex.):

This is page 1 of 4, wonderful!

So, to create a footer in every page use something like:

{\footer\pard\qr Page \chpgn  of {\field{\*\fldinst  NUMPAGES }}\par}

(Remove \qr if you do not want to align the page numbering to the right.)

like image 159
Tero Niemi Avatar answered Oct 16 '22 22:10

Tero Niemi


I got it. It was quite complicated and got a sample from a client that was already doing it. I figure it would be nice to post it here so at least the answer is now out on the NET.

Instead of this: Page \chpgn of \nofpages

I am using this:

{\insrsid2691151 Page }{\field{\*\fldinst {\insrsid2691151  PAGE }}{\fldrslt {\insrsid2691151 1}}}{\insrsid2691151  of }{\field{\*\fldinst {\insrsid2691151  NUMPAGES }}
{\fldrslt {\insrsid11226526 2}}}{\insrsid2691151 \par }}
like image 43
Opy Avatar answered Oct 16 '22 23:10

Opy


For those still having problems with previous solutions, here's another way of generate "Page x of y" as footer for all pages.

{\rtf1\ansi\deff0
{\footer\qr{
Page {\field{\*\fldinst {PAGE}}{\fldrslt {Refresh >F9<}}} of {\field{\*\fldinst {SECTIONPAGES}}{\fldrslt {Refresh >F9<}}}
}\par}
{{Hello, RTF!}\par}
}

Note that for some reason, some RTF viewers may not update correctly the current page or number of pages of a document. The code above assure these fields will be updated.

like image 45
PFROLIM Avatar answered Oct 16 '22 23:10

PFROLIM