SAS Office Analytics, SAS Add-In for Microsoft Office, and other integrations

Determining page numbers in RTF

Reply
New Contributor
Posts: 2

Determining page numbers in RTF

I'm trying to write a macro based on http://www.pharmasug.org/proceedings/2012/AD/PharmaSUG-2012-AD12.pdf to compile all my individually run rtf files into one with a TOC appended.  My problem resides in the rtf code for the number of pages, as the number of pages is not rendered until the file is open.  The author of this paper just uses the infile statement on the rtf and finds the number of pages for the TOC on a line in the rtf code.  Is there something that I'm missing in this paper to find this, since my rtf code looks like :  \b\sb0\sa0\qr\f1\fs16\cf1{Page {\field{\*\fldinst { PAGE }}} of {\field{\*\fldinst { NUMPAGES }}} }

The code in the paper shows it as :\pard\plain\intl\sb10\sa10\qr\f2\fs16\cf1 (Page 1 of 4)\cell

The way that I'm setting my page x of y in rtf is using proc template and reissuing the style for pageno.

       style pageno from pageno /
         font=fonts("strongfont")
         pretext="Page "
         posttext=" of !{lastpage} ";

Any help would be appreciated.  Thank you!

Super User
Super User
Posts: 7,720

Re: Determining page numbers in RTF

Hi,

Yes, not used the method you show to get page numbering in your RTF and that is probably why you get differing tagset output.  I would suggest to do this.  In your footnote statement have:

footnote1 j=r "^{thispage} of ^{lastpage}";

You should then see in your tagset output:

\pard\plain\intbl\keepn\sb10\sa10\qr\f1\fs16\cf1{Page {\field{\*\fldinst { PAGE }}} of {\field{\*\fldinst { NUMPAGES }}}\cell}

You can read the RTF file and count the number of the above to get total pages, although be careful, if your output goes over more than one actual page, you wont see this footnote duplicated in the RTF, however it will in the Word view.  So if from SAS we get 2 pages, but the contents of page 2 are too big Word would split the page, and you would see 1 of 3 in the Word view but the above tagset output would only appear twice.

There are some solutions out there which do all kinds of complicated algorithms on text files to find page number, my recommendation would be to ensure you fix your output before outputting rather than trying to calculate after the event.  So in my outputs I will explicitly fix say 20 rows per output page, this would allow 15 rows to roll over before a page break etc.

New Contributor
Posts: 2

Re: Determining page numbers in RTF

Either ways of assigning the page number (using the style template and putting it in the header) or putting in a title or footnote statement causes the \pard\plain\intbl\keepn\sb10\sa10\qr\f1\fs16\cf1{Page {\field{\*\fldinst { PAGE }}} of {\field{\*\fldinst { NUMPAGES }}}\cell} code to show up the same amount of times in the tagset output.  Thank you though for the suggestion; as I hadn't thought of counting the number of times that it appears in the tagset output.  I can't really 'fix' the output to specific number of pages, as we are using validated macros that dynamically output the number of pages.  I'm still trying to figure out how to dynamically do it.  In my current example the output spans 5 pages, but this code occurs 3 times. 

Super User
Super User
Posts: 7,720

Re: Determining page numbers in RTF

Yes, check what your standard macro is outputting for the numerb of pages.  It sounds like the macro is telling you there are three pages, hence that code appears three times.  Word, when it reads it in however is saying for my page settings I think this should be over five pages and is filling the information out for you, Office being helpful again!  Maybe also check what assumptions your standard macro uses, maybe you are print to a smaller page size, or landscape versus portrait.  Even a slightly larger font could throw the calculation out.

Hope you get it sorted, page numbering is a real pain.

Ask a Question
Discussion stats
  • 3 replies
  • 3952 views
  • 0 likes
  • 2 in conversation