Hello everyone!
I need to convert a .RTF file into a .PDF file. I created the RTF with ODS RTF and proc report. I tried using ODS PDF, but the columns come out pretty weird so I thought using X command would be easier, the problem is, I can't figure out which executable in Microsoft Office10 if the correct one for the x command. Is anyone familair with doing this? Here is the code I have so far:
x '"C:\Program Files\Office\Office14\_______.exe" c:\report\temp.rtf d:\report\tempxx.pdf /Y';
Thank you!
Report writing is not what I'm normally doing so it can be that I miss the point. On a "high level" it's quite simple to add an additional output destination as demonstrated in below code.
I assume if you have embedded output destination specific formatting in your Proc Report then it's another story.
%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;
ods _all_ close;
ods rtf file="&rtf";
ods pdf file="&pdf";
proc print data=sashelp.class;
run;
ods _all_ close;
ods listing;
Sounds like a "clean" Microsoft question.
You may be better off searching for the aswer at support.office.com or other MS focused sites.
Good idea! I have also posted it on the microsoft forums but I keep on getting asked why am I not manually opening the rtf and turning it into a pdf- which I could do, but the whole point it to automate the process.
Is there a reason why you don't use ODS PDF directly with PROC REPORT?
I need both rtf and ods pdf files. I was given the ods rtf and proc report by the company and I just started working for an they have been manually making the pdf files. There are over 10 rtf files that are generated by this code and I thought using X commander would be easier than using ods pdf because I would have to customize each ods pdf code to fit the different rtf files.
OK, but it still might be worth a quick test of direct PDF as you may find you only need to change your ODS statement. If not then revert to your original plan.
Report writing is not what I'm normally doing so it can be that I miss the point. On a "high level" it's quite simple to add an additional output destination as demonstrated in below code.
I assume if you have embedded output destination specific formatting in your Proc Report then it's another story.
%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;
ods _all_ close;
ods rtf file="&rtf";
ods pdf file="&pdf";
proc print data=sashelp.class;
run;
ods _all_ close;
ods listing;
I totally agree with what @SASKiwi's question implies: Try a bit harder and make it work with ODS PDF instead of going for work-arounds too early.
But just for fun here a way of how to do it. It needs Word 2010 or higher installed on the machine where you execute the SAS code.
%let RTF=C:\temp\test6.rtf;
%let PDF=C:\temp\test6.pdf;
%let vbscript=C:\temp\test6.vbs;
ods rtf file="&RTF";
proc print data=sashelp.class;
run;
ods rtf close;
filename vbscript "&vbscript";
data _null_;
file vbscript;
put
"Const WORD_PDF = 17"
/ "Const WORD_IN=""&RTF"""
/ "Const PDF_OUT=""&PDF"""
/ "Set objWord = CreateObject(""Word.Application"")"
/ "objWord.Visible = False"
/ "Set objDocument = objWord.Documents.Open(WORD_IN,,False)"
/ "objDocument.SaveAs PDF_OUT, WORD_PDF"
/ "objDocument.Close False"
/ "objWord.Quit"
;
run;
filename vbscript;
options symbolgen;
data _null_;
/* execute vbs */
call system("&vbscript");
/* clean up: delete rtf & vbs */
call system("del /q &vbscript");
call system("del /q &RTF");
run;
Hello Patrick,
I will try this on Monday morning and see if it works! I have replied to SASKiwi's question as to why I dont just use ods PDF above.
Thank you all for your input and help- seriosuly I wonderful forum,
Donal S.
Hi Patrick,
I tried your code and found it works perfect when the path name does not contain space. Can you help me how to specify the path name with space? i.e. I:\Study Documents\test.rtf
Thanks,
Emma
Spaces and even worse '&' need just some additional quoting as done below:
%let RTF=C:\temp\test & test\test6.rtf;
%let PDF=C:\temp\test & test\test6.pdf;
%let vbscript=C:\temp\test & test\test6.vbs;
/** no changes below the line required */
%let rtf=%unquote(%str("&rtf"));
%let pdf=%unquote(%str("&pdf"));
%let vbscript=%unquote(%str("&vbscript"));
ods rtf file=""&RTF"";
proc print data=sashelp.class;
run;
ods rtf close;
filename vbscript ""&vbscript"";
data _null_;
file vbscript;
put
"Const WORD_PDF = 17"
/ "Const WORD_IN="&RTF""
/ "Const PDF_OUT="&PDF""
/ "Set objWord = CreateObject(""Word.Application"")"
/ "objWord.Visible = False"
/ "Set objDocument = objWord.Documents.Open(WORD_IN,,False)"
/ "objDocument.SaveAs PDF_OUT, WORD_PDF"
/ "objDocument.Close False"
/ "objWord.Quit"
;
run;
filename vbscript;
options symbolgen;
data _null_;
/* execute vbs */
call system(""&vbscript"");
/* clean up: delete rtf & vbs */
call system("del /q "&vbscript"");
call system("del /q "&RTF"");
run;
Thank you so much. It works great!
Best,
Emma
Hi Patrick,
Could you please help me how we can use this code to convert txt files to pdf
at the same timce can we give pagenation in output pdf by using vbscript ?
Thanks in advance
Please don't post new questions into an existing thread but post a new question and copy/paste a reference link to the existing thread.
SAS has a ODS PDF destination so not sure if you need to use any non-SAS tools at all. Just post your question into forum "ODS and Base Reporting".
You will also need to provide a bit more detail of what you have and what you need; best already demonstrating some own work and thinking and if possible also providing sample data in form of a data step and then a description of the desired output.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: