Adding a TIFF Preview to Encapsulated Postscript Graphics Within the SAS® System Gerhardt Pohl, Eli Lilly and Company, Indianapolis, IN
Total Page:16
File Type:pdf, Size:1020Kb
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 preview 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 INTRODUCTION 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 Microsoft Office, 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 "c:\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 fonts (hwps001) rather than simulated software fonts (swiss). Use of data _null_; retain lfile; hardware fonts results in scalable, high quality text without jagged infile tiff 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 section; %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.