Page x of y in pdf

Reply
Contributor
Posts: 21

Page x of y in pdf

Hi,

ods escapechar='^';
I used "Page ^{thispage} of ^{lastpage}" to get the page nos. But Iam not able to get the page nos for the following code. But it worked for me for other sample code.

goptions /*reset=all*/ gsfmode=replace
targetdevice=emf device=/*cgmof97l*/emf /*gaccess=gsasfile*/
colors=(black) ftitle=simplex ftext=simplex htext=1 /*hsize=0 vsize=0 */xpixels=1450 ypixels=/*1350*/1000;

symbol interpol=join repeat=&n1 h = 2 width=1 mode=include color=black;

symbol2 interpol=join h=2 width=1 l=1 repeat=&n2 color=black value=dot;

axis1 label=(h=3 'Time (days)' font=Arial ) order=(0 to 120 by 10) MINOR=NONE;
axis2 label =(angle=90 h=3 "concentration (ng/mL)") logbase=10 logstyle=expand minor=none;

ODS pdf FILE = "/vob/CSMS995L/CSMS995L2102/report/export/pkpd/pgm_cp/temp.pdf" startpage=never;

title1 j=r f=Arial "Page @{thispage} of @{lastpage}";

footnote1 h=2 j=l f=Arial "&tit" j=r f=Arial 'Page ^{thispage} of ^{lastpage}';



proc gplot data=pk1 /*gout=work.tempc */;
by trt;
plot conc_*stm4n=sid1a / /*name="g1" */ vaxis=axis2 haxis=axis1 nolegend /*annotate=anno*/;
plot2 median*stm4n=sid1a / vaxis=axis2 haxis=axis1 nolegend /*annotate=anno1*/;
format stm4n best. conc_ 6.2 trt $trt.;
title5 h=2 f=Arial "Treatment: #byval1";
run;
quit;
ods pdf close;
Valued Guide
Posts: 2,106

Re: Page x of y in pdf

In the footnote statement, you need to use double quotes to get the escape character and macro variables to be resolved.
SAS Super FREQ
Posts: 8,646

Re: Page x of y in pdf

Also, you can only have 1 declared ESCAPECHAR character -- in your code, you have:
[pre]
ODS ESCAPECHAR='^';
[/pre]

Therefore all uses of {THISPAGE} or {LASTPAGE} for this program should be preceded by ^ ...check your code, in a few places, you seem to also use the @ sign as an ESCAPE character.

If you do not use the declared ESCAPECHAR, you may see the @{THISPAGE}, etc in your text.

cynthia

PS:
Your ESCAPECHAR text does NOT have to be in double quotes:
[pre]
title '^{thispage}'; /* OK */
title "^{thispage}"; /* OK */
title "^{thispage} For: &mymacvar"; /* OK */

title '^{thispage} For: &mymacvar'; /* NOT OK */

[/pre]

However, if you have a Macro variable reference in the title or footnote string, then you will NEED double quotes. ESCAPECHAR characters will be recognized, even if they are in single quotes.
Contributor
Posts: 21

Re: Page x of y in pdf

Hi,
I have modified my code according to your suggestions. But still page numbers are not comming.

Pl help in this.

Thanks.
SAS Super FREQ
Posts: 8,646

Re: Page x of y in pdf

Hi:
I had ODS RTF on my mind...here's why: ODS RTF will use your inline formatting for page x of y as long as you use the NOGTITLE and NOGFOOTNOTE options. These options (which are HTML or RTF options) cause the SAS TITLE and FOOTNOTE to be rendered by the destination. Otherwise, if you do NOT use these options or you cannot use the options (as is the case with LISTING and PDF), then the in-line formatting commands (such as page x of y) will not be respected.

At it states in this Tech Support note:
http://support.sas.com/kb/33/986.html

"By default, titles and footnotes are embedded in the images created by SAS/GRAPH procedures. When inline style commands are used to change the style of titles or footnotes or to add PAGEOF information, the commands are written as text to the respective titles and footnotes."

This causes the behavior you are seeing in which the page numbers do NOT appear in the PDF file. The workaround is to switch to ODS RTF and use the NOGTITLE and NOGFOOTNOTE options. (You could also switch to ODS HTML and use NOGTITLE and NOGFOOTNOTE options, however, since ODS HTML does not have page numbering, your page x of y commands would be ignored.)

The simplified code below shows how the page numbering can be made to work with RTF and does not work with PDF.

[pre]
goptions reset=all;
options nodate nonumber pageno=1;

** Make some data for the GPLOT;
proc sort data=sashelp.shoes out=shoes;
by product;
where product in ('Boot', 'Sandal') and
region in ('Asia', 'Canada', 'Pacific');
run;

ods listing close;
%let title = My Title;
** Use nogtitle and nogfootnote to have titles/footnotes rendered by ODS;
** instead of by SAS/Graph. Note that PDF does NOT support these 2 options;

ods rtf file="c:\temp\temp_pgno.rtf" nogtitle nogfootnote;
ODS pdf FILE = "c:\temp\temp_pgno.pdf";

** declare the ESCAPE character as caret ^;
ods escapechar='^';

** Use the page x of y in-line formatting commands within the code;
** NOGTITLE and NOGFOOTNOTE will cause RTF to render the in-line formatting.;
** But PDF will only pass the text strings to SAS/GRAPH where they will be embedded;
** as text in the image (not as page x of y page numbering.;
title1 j=r f=Arial "Page ^{thispage} of ^{lastpage}";
footnote1 h=2 j=l f=Arial "&title" j=r f=Arial 'Page ^{thispage} of ^{lastpage}';

proc gplot data=shoes ;
by product;
plot sales*returns=region ;
plot sales*inventory=region;
run;
quit;
ods _all_ close;
[/pre]

If you notice that the page numbers do not appear correctly when the RTF file is first opened in Word, you just have to go into Print Preview or otherwise force the document to repaginate and the page numbers will be corrrect.

cynthia
Post a Question
Discussion Stats
  • 4 replies
  • 470 views
  • 0 likes
  • 3 in conversation