BookmarkSubscribeRSS Feed
Nobody
Calcite | Level 5
Is there a SAS style attribute or RTF control string that will add a watermark to an RTF document? If not, has anyone heard of this being done and could you suggest an approach?
9 REPLIES 9
Cynthia_sas
SAS Super FREQ
Hi:
A watermark attribute does exist. But, it only works for the HTML destination (not RTF). In ODS HTML, the watermark attribute allows you to "specify whether or not to make the image that is specified by BACKGROUNDIMAGE= into a "watermark." A watermark appears in a fixed position as the window is scrolled." (this description is straight from the documentation.) The value for WATERMARK is either ON or OFF (because it works in conjunction with BACKGROUNDIMAGE).
However, there is one thing you can try. Since Microsoft Word can read an HTML file, you could create an HTML file using BACKGROUNDIMAGE and WATERMARK (as shown below) and then open the HTML file with Microsoft Word. Once it's in Word, you can either save it as a .DOC file or save it as an RTF file. The image will be tiled in the browser and will also be tiled when Word opens it. Therefore, you should try to make the image very close in size to what you want the watermark to be in order to minimize tiling.

Here's the sample code...where I have kermit.jpg specified below, you would insert the name of your image file to be the watermark. You need the change to the style template because the table (in this case, from PROC REPORT), sits on the BODY of the HTML document. Therefore, you want to modify the BACKGROUNDIMAGE for the BODY of the document.
[pre]
ods path work.wmark(update)
sashelp.tmplmst(read);

proc template;
define style styles.water;
parent=styles.sasweb;
style body from body /
backgroundimage='kermit.jpg'
watermark=on;
end;
run;

ods msoffice2k path='c:\temp' (url=none)
file='test_watermark.doc' style=styles.water;

proc report data=sashelp.class nowd;
column name age height;
run;
ods msoffice2k close;

[/pre]

I do not know whether there's a way using RTF control strings to specify a watermark.

In the Microsoft Word help (I start there because Microsoft wrote the RTF specification) -- it says that watermarks are intended for a PRINTED document. MS Word help says:
"On the Format menu, point to Background, and then click Printed Watermark"
If I follow those instructions and insert a picture to be used as a watermark AND then save the file as an RTF file, it looks to me like my picture has been converted to RTF format and is inserted with a \pict control string. However, \pict does NOT point to my original picture...it is followed by the RTF graphics version of the picture. According to the RTF 1.5 spec, which I found here,
[pre]http://www.biblioscape.com/rtf15_spec.htm
[/pre]
"An RTF file can include pictures created with other applications. These pictures can be in hexadecimal (the default) or binary format. Pictures are destinations, and begin with the \pict control word. The \pict keyword is preceded by \*\shppict destination control keyword as described in the following example."

So if you can live with creating an HTML file and then instructing folks to open the HTML file with Word, this may be a solution that works for you. If you need to generate an RTF file with a watermark, then I do not believe that ODS can help you right now. I do not know whether future plans for RTF (or some other MS Word Markup Language) include plans for Watermark support.

cynthia
Jianmin
Obsidian | Level 7
%let cln=170; 
%macro tt; 
data code; 
do i=0 to 15; col0=put(i, hex1.);  output;  end; keep col0; label col0="_";  run; 

%do k=1 %to &cln; 
data _null_; call symput("KK", put(&k, hex2.)); run; 
data u&k; 
do i=0 to 15; 
  a=put(&k, hex2.); b=put(i, hex1.); col=compress('<'||'u1F'||a||b||'>'); 
  col&k=unicode(col,'paren'); output; 
end; 
keep col&k;  label col&k="1F&kk"; 
run; 
data code; merge code u&k; run; 
%end; 
%mend tt; 
%tt; 

ods rtf file="~/sasout/A Few Unicode.rtf";
proc report data=code; 
col col0-col&cln ; 
define col0-col&cln / display; 
title "A Few Unicodes";
run; 
ods rtf close; 
run; 

Hi Cynthia, 

 

The other day I asked you a question about how many columns an ODS RTF REPORT table supports.  I soon found the answer myself, and the quick answer is a lot of columns, with a little caveat: proc report will wrap the columns to fit the page.  Attached is an SAS program for a table of 170 columns on a few pages.   

Then I saw this line of discussion.  I know very little about ODS RTF, but I wonder if I can add a piece of code into the header section of the REPORT table, which I did manually, so I can have a watermark on every page of the table.  See the attached RTF file, and the image of the watermark is one of the Unicodes.  I wonder if SAS can add a feature of adding code in the header or it already exists.  Please let me know. 

Many Thanks

Jianmin Long

Cynthia_sas
SAS Super FREQ
Hi: Sorry, I did not see this since it was inserted into the middle of a posting from 2006. As far as I know, you can insert field codes for page, date and other items into an RTF file because they are supported in the RTF specification. The newest ODS destination, ODS WORD makes a true .XLSX file that conforms to Office Open XML standard. If that standard has a way to insert watermarks into the header or alter the header's XML, then there might be a way to do it. I did not see an option or suboption to insert a watermark into an ODS WORD file. So you might want to ask Tech Support about this.
Cynthia
Jianmin
Obsidian | Level 7

Hi Cynthia,  Thanks for your reply.  I have read those comments before and I thought that was then.  Recently I have heard a lot good things about ODS TAGSETS.RTF which supports image file through template, for one image file as background?  

After I asked the SAS way to insert some code in SAS output headers, I found a way to get around.  See the attached SAS code and the output. 

RTF specs didn't mention Watermarks, but Shapes.  The second attached file has a few more shapes inserted, plus a TOC page it tells where to click. 

Many Thanks

Jianmin 

options orientation=landscape; 
ods rtf file="~/sasout/0test.rtf"; 
%let title1=Table 1: Student Data;
%let title2=Table 2: 2004 Car Data;
proc report data = sashelp.class;
title &title1; 
run;
proc report data= sashelp.cars(obs=30); 
title &title2; 
run; 
ods rtf close;

data _readrtf_; 
infile "~/sasout/0test.rtf" missover length=l end=eof lrecl=2000; 
input line $varying2000. L; 
line=tranwrd(line, "\clcbpat8", ""); 
line=tranwrd(line, "\clcbpat17", ""); 
run; 

data _null; set _readrtf_; 
retain __n 0; 
file "~/sasout/0test.rtf" ; 
put line; 
if line=:"{\header\" then do; __n+1;
%txt(2, 2000, 3200, 60, 4500, z=1, fs=32, an=-90, line=1, lr=128, lg=0, lb=0, o=1, r=255, g=255, b=255, lw=200, 
txt=%str(Draft Listing - Please Review));
if __n=1 then do; %wm(wm=&title1);  end; 
else if __n=2 then do; %wm(wm=&title2); end; 
end; 
run; 

 

Jianmin
Obsidian | Level 7

O by the way, SAS ODS TAGSETS.RTF supports watermark nicely.  See the code:

ods tagsets.rtf file="~/sasout/test.rtf" style=rtf options(watermark="Student Data");
proc report data = sashelp.class;
run;
ods tagsets.rtf close;
run;  

wayne_sas
SAS Employee
Cynthia asked me to reply.


Currently, there is no watermark support in the RTF files created by SAS.

The 1.6 RTF Specification supported by MS Word does not mention watermarks. But, you can apply a watermerk using the Format pulldown in Word and selecting "Background". You can follow the arrows from that point and all is good.

You can even save the DOC file as RTF and have the watermark preserved. When you re-open the RTF file, the watermark remains.

This is done by combination of techniques. Word embeds the image a hex translation with a \pict syntax, but makes it a a shape object with specific characteristics. It is placed in various parts of the section information and makes use of stored name and value pairs to pass information back to Word. The stored name/value pairs are part of Visual Basic.

The 1.6 RTF spec is careful about supporting older syntax in newer versions. We prefer to not support techniques we cannot be certain will be carried forward.

The best way to put a watermark on the document is currently in Word and saving as either an RTF file or DOC file. There are modifications that can be done in Word but will be lost when saved to an RTF file. This is not one of them.
PhilMason
Obsidian | Level 7
I wonder if there is a way to call a VBA macro when producing some RTF. It is pretty easy to make a VBA macro in word to add a watermark. Can we tell ODS/RTF to call this macro somehow? I know we can do it from windows by opening word with DDE, loading the RTF and calling the macro - but is there another way?
Cynthia_sas
SAS Super FREQ
Hi, Phil:
My question would be: what happens if SAS is out of the picture.?

In other words, if you create a little file by manually typing in Word and then define a macro in that document to load the watermark. If you then save that Word file as an RTF file, do the macro instructions carry over into the RTF version or do you get that snarky message that some features in the Word doc will be lost?

Just curious. I don't -do- VBA or Word macros because I'd have to jettison something in my brain to make room for a new language.

cynthia

(I suspect that you'll get the \pict image in the RTF file and not the instruction to use the macro -- but that's just speculation on my part.)
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest checking the SAS support website for technical and conference paper resources on ODS and calling a VBA macro. Here is a Google advanced search argument (limited to searching the SAS.COM site only) which yielded some matches:

ods rtf call vba macro site:sas.com

Scott Barry
SBBWorks, Inc.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 6742 views
  • 0 likes
  • 6 in conversation