Images and URL links might be missing from PDF output when using the LASTPAGE inline function


The preproduction inline style function LASTPAGE is available for use in the RTF and PRINTER destinations (PCL/PDF/PS) in SAS® 9.1.3. If the function is used in a TITLE or FOOTNOTE statement in the PRINTER destinations and SAS/GRAPH® is used to generate images, or if the PREIMAGE, POSTIMAGE, or BACKGROUNDIMAGE option is used to include an image in the same file, the image might be missing.

If the function is used in a TITLE or FOOTNOTE statement in the PRINTER destinations and one or more URLs are included as part of a table, the links might not appear.

To circumvent the problem, do one of the following:

The test code below creates two PDF files. The SAS Log is captured from the creation of the first PDF file and is used to determine the number of pages (LASTPAGE), which is stored in a macro variable. The macro variable is then used in a FOOTNOTE statement to mimic the preproduction LASTPAGE inline style function when the final PDF file is created.

/* Start with a clean SAS Log. */
dm "cle log;";

/* Create the PDF file initially to extract the number of pages. */
ods escapechar="^";
filename test "c:\temp\file.log";

/* Direct the SAS Log file to a text file with PROC PRINTTO. */
proc printto log=test new; 
run;

ods noresults;
ods pdf file="file.pdf";

/* NN is a placeholder for LASTPAGE */
proc print data=sashelp.cars;
   footnote j=r "^{thispage} of NN";
run;

ods pdf close;
ods results;

proc printto; 
run;

/* Use the SAS Log file to determine the total number of pages (LASTPAGE) value. */
data _null_ ;
   length line $400;
   infile test length=lg lrecl=1000 end=eof;
   input @1 line $varying400. lg;
   if (index(line,"NOTE: ODS PDF printed") > 0) then do;
      /* Find the beginning position of the page number */
      pos=anydigit(line);
      /* Find the ending position of the page number */
      pos_pages=indexw(line,'pages');
      /* Extract the page number using the SUBSTR function */
      newvar=substr(line,pos,pos_pages-pos);
      /* Check the page number total */
      put "success!" pos= newvar= ;
      /* Put the page number total into a macro variable */
      call symputx("totpage",newvar);
   end;
run ;

%put &totpage;

/* Overwrite the original file (or write the first PDF file to a temporary directory). */
ods pdf file="file.pdf";

/* Put the total page number back into the original footnote (or title) */
proc print data=sashelp.cars;
   footnote j=r "^{thispage} of &totpage";
run;

ods pdf close;