Adding a TIFF Preview to Encapsulated PostScript Graphics within the SAS® System Gerhardt Pohl, Eli Lilly and Company, Indianapolis, IN

ABSTRACT Contrast the behavior of a CGM graphic with that of an EPS graphic There is increasing use within the pharmaceutical industry of PDF when inserted into MS Word (Figure 2). The underlying code for the (Portable Document Format) for clinical trial reports and other EPS graphic is embedded in the MS Word document file without regulatory documents. The natural graphics format for figures to be any translation. When the document file is then rendered as a PDF, included in such documents is PostScript. Unfortunately, in work the code is passed through the rendering software without environments where Microsoft Word is the primary authoring tool, translation. The exact graphic code at creation is the same code PostScript graphics can be problematic. PostScript graphics are not visualized by the final audience assuring fidelity. visible in Microsoft Word documents prior to printing or rendering as a PDF. To overcome this difficulty, a visible of the graphic can be inserted into the Encapsulated PostScript (EPS) file prior to Figure 2: EPS avoids translation when inserted into MSWord and insertion into MS Word. A technique will be demonstrated using the subsequently rendered into PDF DATA step to bind SAS/GRAPH® EPS and TIFF files into an EPS file with TIFF preview. When inserted into MS Word the TIFF portion of the file is displayed while the EPS portion passes without *.EPS

translation or distortion into the final PDF. File

System Insert Filter EPS provides an important advantage over other graphics transport formats when the final destination is a PDF. Since PostScript is the native graphics format for figures in PDF, graphics in this format do not need to be translated in order to appear within the PDF. To EPS demonstrate this, consider the pathway for a CGM graphic which is Word

output from SAS/GRAPH, inserted into MS Word and then rendered Document into a PDF (Figure 1). During this process the graphic is actually PDF Rendering translated twice from CGM to WMF by the insert filter in MSWord and from WMF to PS by the PDF rendering software. The translation to WMF allows the graphic to be visible and edited within , but multiple translations increase the possibility of PS error. Indeed, features of the original format may not exist in the PDF following formats forcing substitutions of graphics primitives to simulate features. Minimizing the number of translations is an effective strategy to avoid errors giving the author assurance that the graphic seen by the final reader is the same graphic that was seen The challenge in using EPS in an environment where MS Word is at creation. the primary authoring tool is that since the graphic is not translated to WMF, it is not visible onscreen within MS Word. Instead, a placeholder box is visible (Figure 3). This placeholder box has the Figure 1: Translation of a CGM when inserted into MS Word and dimensions of the final graphic assuring proper space is reserved subsequently rendered into PDF and maintaining correct pagination. The box contains useful information explaining what is occurring. In particular, the viewer is reassured that the code for the graphic is, indeed, being held within *.CGM the document file and will be visible when printed to a PostScript

File printer. If printed to a non-PostScript printer, however, only the

System placeholder box and comments will be visible. Note also that within Print Preview in MS Word that the placeholder box and not the Insert Filter graphic is visible. EPS graphics can be resized within Microsoft Office but cannot be otherwise edited. This provides an added measure of security in the document preparation process. WMF Word Document PDF Rendering

PS PDF

Figure 3: Placeholder box in MSWord for EPS file without Figure 5: Adding a TIFF preview to an EPS graphic with embedded preview GhostView.

Title: PS PROC GPLOT File

Creator: System

Preview: GhostView This EPS picture was not saved with a preview included in it. Comment: PS TIFF This EPS picture will print to a File PostScript printer, but not to System other types of printers. Insert Filter

PS TIFF Word Document PDF Rendering

PS PDF

GhostView produces a relatively good preview; however, In a production environment where large numbers of figures are generated, the extra steps and burden of maintaining additional software are cumbersome. This paper discusses a method to add a TIFF preview to a SAS/GRAPH EPS using only SAS software.

DETAILS OF METHOD At a high level the method consists of generating an EPS file without preview in SAS/GRAPH, generating a matching TIFF graphic also within SAS/GRAPH, then using the DATA step as a file editor to embed the TIFF graphic into the EPS file to create an EPS with PREVIEWS IN EPS TIFF preview. Details of these processes are discussed with The EPS file specification allows for the inclusion of either a TIFF ( example code. or WMF preview of the PS graphic. As shown in schematic form, an EPS file is essentially a PS file with optional binary header material CREATING A TIFF DRIVER and an optional preview (Figure 4). When an EPS with preview is A necessary first step in the process is to create a TIFF driver that inserted into MS Word, MS Word displays the preview rather than can create previews in the sizes to match those possible in the the placeholder box. SAS/GRAPH EPS drivers. Detailed code for this is given as this is a step that may be unfamiliar to most SAS software users. Users unfamiliar with the location or functioning of their SAS software Figure 4: Structure of an encapsulated PostScript file installations are encouraged to seek help from their system administrators. The example code was written for SAS version 6.12 under the Windows 95 operating system. Appropriate changes may Header PS Portion Optional Preview be necessary to adapt to other platforms.

libname gdevice0 ":\sas\graph"; proc gdevice c=gdevice0.devices nofs; Having previews is useful when assembling large documents with copy tiffb multiple figures. Otherwise one cannot be certain which graphic has from=sashelp.devices been inserted in each location. A preview allows one to see the newname=tiffprev; graphics confirming that each is in the proper position. SAS/GRAPH modify tiffprev des="TIFF for EPS Preview" does not currently support creation of a preview for EPS graphics. gsflen=1024 There are a number of third party solutions that one can use to bind xmax=11 in a preview to a SAS/GRAPH EPS. SAS technical support ymax=11 in documents recommend the freeware program GhostView (Figure 5). xpixels=1045 ypixels=1045 lcols=130 lcols=130 prows=130 pcols=130 cback=white colors=(black)

; input; run; if _n_=1 then lfile=length+1; quit; else lfile=lfile+length+1; CREATING AN EPS GRAPHIC FILE call symput("leps",lfile); Most details of the GOPTIONS and PROC GPLOT are omitted for run; space. Note the device and the recommendation to use hardware (hwps001) rather than simulated software fonts (swiss). Use of data _null_; retain lfile; hardware fonts results in scalable, high quality text without jagged infile recfm=f lrecl=1024 nopad; edges and dramatically smaller file sizes. input; if _n_=1 then lfile=1024; filename eps "c:\test.eps"; else lfile=lfile+1024; GOPTIONS gsfname=eps call symput("ltiff",lfile); device=psepsf run; ftext=hwpsl009 ftitle=hwpsl009; ; When writing the final EPS file with preview, the header is written PROC GPLOT DATA=DATA1; first including the file size parameters. Next the original EPS file is PLOT _YVAR*_XVAR = GRPVAR; added; and, finally, the TIFF preview is written. Note that the TITLE1 'This is Title'; comment shows the binary header format for an EPS with preview. run; The technique is the same as demonstrated above for reading and copying external files. The result of this code is an EPS file named test.eps. filename withprev 'c:\withprev.eps';

CREATING A MATCHING TIFF FILE * Start with binary header; The remainder of the code steps are best realized as a macro that is called after the creation of the original EPS graphic. The data _null_; GOPTIONS HSIZE and VSIZE of the original EPS graph can be file withprev recfm=n; captured using system functions. The TIFF version of the graphic is then created using PROC GREPLAY using the SAS catalog entry * Bytes 0-4: Marker for binary header; from the previous EPS graphic. * Bytes 4-7: Byte position in file of PostScript language ; %let * Bytes 8-11: Byte length of PostScript oldhsize=%sysfunc(getoption(hsize,keyword)); language section; %let * Bytes 12-15: Byte position in file for oldvsize=%sysfunc(getoption(vsize,keyword)); start of WMF screen representaion; * Bytes 16-19: Byte length of WMF section; filename tiff 'c:\test.tif'; * Bytes 20-23: Byte position of TIFF goptions device=tiffprev representation; gsfname=tiff * Bytes 24-27: Byte length of TIFF section; gsfmode=replace * Bytes 28-29: Checksum of header &oldhsize (XOR of 0-27) -- Not used; &oldvsize; b0_4='C5D0D3C6'x; * Replay graphic as an output TIFF file; b4_7=put(31,ib4.); greplay nofs; b8_11=put(&leps,ib4.); replay _last_; b12_15=put(0,ib4.); run; b16_19=put(0,ib4.); quit; b20_23=put(31+&leps,ib4.); b24_27=put(<iff,ib4.); OVERLAY FOR TIFF b28_29='FFFF'x; The TIFF graph generated from the previous code is a coarse put @1 b0_4 rendition of the original EPS graphic. This may be disturbing to @5 b4_7 viewers of a MS Word document into which it is inserted. @9 b8_11 Uninformed viewers may not realize that the graphic viewed within @13 b12_15 MS Word is not the final high quality graphic that will appear in the @17 b16_19 final rendering. To provide guidance to users, an overlay for the TIFF @21 b20_23 preview can be created which includes statements like the original @25 b24_27 guidance in the MS Word placeholder box, “This preview will print as @29 b28_29; a high resolution graphic when printed on a PostScript printer or run; rendered as a PDF.” The text overlay is created by overlaying a slide of the text onto the TIFF preview in PROC GREPLAY. * Append EPS file;

BINDING TIFF PREVIEW TO EPS data _null_; infile eps recfm=f lrecl=&leps With the pieces prepared one is ready to bind the TIFF preview to sharebuffers; the original EPS file. Some necessary parameters to include in the file withprev recfm=f lrecl=&leps mod; header of an EPS file with preview are the file lengths of the input; PostScript and TIFF portions of the file. The sample code below put _infile_; shows a method of determining these using null DATA steps. run;

data _null_; * Append TIFF file; retain lfile; infile eps recfm=v length=length nopad data _null_; missover; infile tiff recfm=f lrecl=<iff

sharebuffers nopad; Figure 7: EPS with TIFF preview as printed to a PostScript file withprev recfm=f lrecl=<iff nopad printer or rendered as a PDF mod; input ; put _infile_; run; This is Title

quit; 0.47

Figure 6 shows the resulting file as viewed within MS Word. Note the overlay of the TIFF graphic with instructions for viewing the high resolution portion of the graphic. Figure 7 shows the PostScript version of the graphic as it appears when printed to a PostScript 0.46 printer or rendered as a PDF.

Figure 6: EPS with TIFF preview as displayed in MS Word 0.45

Y-axis Label 0.44

0.43

0.42 1234 X-axis Label _GRPVAR AA30 AD30 BD15 Z000

CONCLUSION The method shown here allows one to include a TIFF preview in a SAS/GRAPH EPS without the use of additional software. The results are not of high quality. In one respect this may be useful in that the low quality of the resulting TIFF preview provides a warning to users of any errors in document processing. For example, if one were to erroneously print to a non-PostScript printer the resulting TIFF image with overlay would make that immediately apparent. Similarly, if a MS Word document were to be mistakenly circulated as the final rendition, the TIFF overlay would again make it immediately obvious that the final PDF rendering was not being viewed.

Despite its limitations, this method fills an important unmet need within the SAS software system. With the increasing use of PostScript and PDF within the pharmaceutical industry, perhaps, future versions of SAS/GRAPH will include an option for creating high quality previews.

ACKNOWLEDGMENTS Special thanks to Vishwaneth Iyer for assistance in developing this method.

CONTACT INFORMATION Gerhardt Pohl, Ph.D. Eli Lilly and Company Lilly Corporate Center, DC 2248 Indianapolis, IN 46485 Phone: 317-277-5113 Email: [email protected]